Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7832843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:26:26+00:00 2026-06-02T12:26:26+00:00

I am trying to implement a macro which will allow me to run several

  • 0

I am trying to implement a macro which will allow me to run several logistic regression models that have the same outcome but a different main explanatory variable (the covariates would be common for all models) for several datasets. I have written a scan and eval macro that scans two global variables but it’s not quite working. The code is shown below:

%let numbers=5 7 8 9 10 12 13 14 16 18 19 24  26 
32 33  35 37  39  41  44 45  48 50 52 
55 56  58  66 67 68 ; 

%let list=voting national local safe street violence say free;

%macro logistic;    
%let j=1;
%let m=1;
%let first=%scan(&list,%eval(&j));
%let second=%scan(&numbers,%eval(&m));
%do %while (&first ne );
%do %while (&second ne );

proc logistic data=socialcapital&second. descending;
model depression= &first. agec married edu inc_2 inc_3 inc_4 inc_5/risklimits;
ods output ParameterEstimates=mv_model1&second._&first.;
run;

%let j=%eval(&j+1);
%let m=%eval(&m+1);
%let first=%scan(&list,%eval(&j));
%let second=%scan(&numbers,%eval(&m)); 
%end;
%end;
run;

%mend;  
%logistic;

The global variable numbers refers to the “socialcaptial” dataset that I am using. Each dataset represents a country and so each number in the “numbers” global variable refers to a dataset. The global variable list refers to the list of main explanatory variables that I want to include in the model, one main explanatory variable per model. What I am looking to get is 8 separate multivariable logistic regression results for each country.

However, it appears that the scan function is not working properly for me so I know that I have done something wrong, but I am not sure what. It seems that the macro assigns 1 variable from &list to 1 dataset from &numbers until it runs out of variables from &list and simply runs the model with just the covariates instead of running all 8 models using the dataset 5, then running all 8 models again using dataset 7, and so forth.

Basically, I have messed up something with the numbering and I am not quite sure how to proceed with this macro. I know that I can get rid of the &numbers global variable by using a “by statement” in proc logistic with a stacked dataset but I would really like to learn how to get this to work for future models where that might not be an option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:26:27+00:00Added an answer on June 2, 2026 at 12:26 pm

    Maggie,

    I believe the code below will do what you want. I commented out the LOGISTIC procedure and put in a PUT statement for testing, and it seems to resolve the way that I expect you think it should.

    %let numbers=5 7 8 9 10 12 13 14 16 18 19 24  26 
    32 33  35 37  39  41  44 45  48 50 52 
    55 56  58  66 67 68 ; 
    
    %let list=voting national local safe street violence say free;
    
    %macro logistic;
       %let j=1;
       %let first=%scan(&list,%eval(&j));
       %do %while (&first ne );
          %let m=1;
          %let second=%scan(&numbers,%eval(&m));
          %do %while (&second ne );
    
            /*
             proc logistic data=socialcapital&second. descending;
             model depression= &first. agec married edu inc_2 inc_3 inc_4 inc_5/risklimits;
             ods output ParameterEstimates=mv_model1&second._&first.;
             run;
            */
             %put J=&j - M=&m - FIRST=&first - SECOND=&second;
    
             %let m=%eval(&m+1);
             %let second=%scan(&numbers,%eval(&m));
          %end;
          %let j=%eval(&j+1);
          %let first=%scan(&list,%eval(&j));
       %end;
       run;
    %mend;
    
    %logistic;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a macro which expands a unlimited list of triplet-arguments
when trying to implement an Aspect, that is responsible for catching and logging a
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
I have a java program which I run on a home server. I have
I ran into some trouble trying to implement a smart equality test macro-type template
We have a macro for signalling errors in a common utilities library that goes
I'm trying to write a macro in Lisp that re-implements let using itself. This
That's my first approach with GD stuff. I'm trying to implement resize and crop
Trying to implement a MSMQ-backed WCF PubSub. I understand that net.msmq is one-way; however
I am trying to implement a JSON-RPC solution, using a server connector object which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.