BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Polina_UH
Obsidian | Level 7

Dear all,

 

I'm trying to run multiple models in a macro using macro variable as a predictor. However, instead of 14 models I get one model with 14 predictors plus covariates. Here is my code:

 

%let biomarker = TotalC nonHDLC RemnantC VLDLC ClinicalLDLC LDLC HDLC TotalTG VLDLTG LDLTG HDLTG TotalPL VLDLPL LDLPL;


%macro poisson ;
proc genmod data = met;
ods output ParameterEstimates=parm;
model comorbidity = &biomarker gestational_age birth_year child_sex/ alpha=0.0017 dist=poisson; run;
%mend poisson;

%poisson

 

Here is my output:

 

Polina_UH_0-1589978327466.png

 

I would really appreciate an advice how to modify my code to obtain 14 models with each of the biomarkers as a separate predictor plus covariates. 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You need a macro %DO loop.

 

%let biomarker = TotalC nonHDLC RemnantC VLDLC ClinicalLDLC LDLC HDLC TotalTG VLDLTG LDLTG HDLTG TotalPL VLDLPL LDLPL;

%macro poisson ;
     %do i=1 %to %sysfunc(countw(&biomarker));
        %let thisvar=%scan(&biomarker,&i,%str( ));
        proc genmod data = met;   
        ods output ParameterEstimates=parm&i;
        model comorbidity = &thisvar gestational_age birth_year child_sex/ alpha=0.0017 dist=poisson;
        run;
    %end;
%mend poisson;
%poisson
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

You need a macro %DO loop.

 

%let biomarker = TotalC nonHDLC RemnantC VLDLC ClinicalLDLC LDLC HDLC TotalTG VLDLTG LDLTG HDLTG TotalPL VLDLPL LDLPL;

%macro poisson ;
     %do i=1 %to %sysfunc(countw(&biomarker));
        %let thisvar=%scan(&biomarker,&i,%str( ));
        proc genmod data = met;   
        ods output ParameterEstimates=parm&i;
        model comorbidity = &thisvar gestational_age birth_year child_sex/ alpha=0.0017 dist=poisson;
        run;
    %end;
%mend poisson;
%poisson
--
Paige Miller
Polina_UH
Obsidian | Level 7

Thank you so much, it worked!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 881 views
  • 1 like
  • 2 in conversation