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

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=&param; 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 &param; 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);

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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? 

View solution in original post

5 REPLIES 5
Astounding
PROC Star

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.

Cruise
Ammonite | Level 13
I don't quite get it Astounding.
Reeza
Super User
Your parameters are macro variables. Remember they only resolve in double quotes and need an ampersand. The line you indicated does neither.
Reeza
Super User
 date_of_diagnosis_yyyy eq “&n”
Reeza
Super User
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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 5 replies
  • 1369 views
  • 3 likes
  • 3 in conversation