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:
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.
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
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
Thank you so much, it worked!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.