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!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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