I'm trying to repeat the code below 20 times for 20 consequent years. The macro doesn't help. The problem I think is
in the "date_of_diagnosis_yyyy='n' " .
Please help in the code, if you have time. Any idea why this approach doesn't work?
%macro models(param,par,n);
ods output parameterestimates=¶m;
proc genmod data=have;
class zone(ref="0") sex(ref="1") racecat(ref="1") agecat(ref="2")/param=ref;
model n_cases_reg=zone sex racecat agecat
zone|date_of_diagnosis_yyyy/ dist=negbin link=log offset=ln type3;
ods trace on;
where zone ne '9' and date_of_diagnosis_yyyy eq 'n';
run;
ods rtf close;
data ∥ set ¶m;
if pam~ in ("Scale","Intercept") then do;
RR= exp(estimate);
low_rr=exp(estimate-(1.96*stderr));
up_rr=exp(estimate+(1.96*stderr));
end;
run;
%mend models;
%models(param1995,par1995,1995);
.
so forth so on until
.
%models(param2015,par2015,2015);
ODs output ....; proc genmod data=have; By date_of_diagnosis_yyyy; class zone(ref="0") sex(ref="1") racecat(ref="1") agecat(ref="2")/param=ref; model n_cases_reg=zone sex racecat agecat zone|date_of_diagnosis_yyyy/ dist=negbin link=log offset=ln type3; ods trace on; where zone ne '9'; run;
Any reason you can’t run this as above?
The problem does not lie within the macro. The problem lies with the fact that the macro exists at all. If you want a separate analysis for each year, sort your data by year and run GENMOD by year.
date_of_diagnosis_yyyy eq “&n”
ODs output ....; proc genmod data=have; By date_of_diagnosis_yyyy; class zone(ref="0") sex(ref="1") racecat(ref="1") agecat(ref="2")/param=ref; model n_cases_reg=zone sex racecat agecat zone|date_of_diagnosis_yyyy/ dist=negbin link=log offset=ln type3; ods trace on; where zone ne '9'; run;
Any reason you can’t run this as above?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.