Hello Community,
I am stuck trying to pass a temp value in a do loop. Here is what I am trying to achieve:
AGENCY | SCORE |
A | 68 |
A | 78 |
B | 62 |
C | 61 |
Here is my code:
ODS HTML;
%MACRO CAR(AGENCY=);
ODS html file="\\cchd.org\odsdfs$\ODSShared\Surveillance Reports and QA\Surveillance QA\&AGENCY..html" style=Seaside;
ODS title "Contact FR-QC" ;
ods escapechar = "~";
OPTIONS NODATE NONUMBER;
option orientation=landscape;
proc report data=TEST nofs center;
where AGENCY="&AGENCY";
columns AGENCY SCORE;
run;
ODS html CLOSE;
%MEND CAR;
%CAR (AGENCY=A); /*Report for Agency A*/
The Agency list is dynamic and I want to generate the report by agency by looping the observations listed in AGENCY... Any insight is appreciated.
Although you can loop, I'm a fan of the CALL EXECUTE approach since it seems a bit cleaner to me.
Here's an example of that, you can run it to test. Its broken into small steps so you can follow it, but feel free to combine them into one once you understand the concept.
Same idea, except printing a report for each age, sex combination in the SASHELP.CLASS table.
You can create a list of the agencies using PROC SQL, and here's how you loop over such a list:
proc sql noprint;
select agency into :agency_list separated by " "
from have;
quit;
%put &agency_list;
@HabAM wrote:
Hello Community,
I am stuck trying to pass a temp value in a do loop. Here is what I am trying to achieve:
AGENCY
SCORE
A
68
A
78
B
62
C
61
Here is my code:
ODS HTML;
%MACRO CAR(AGENCY=);
ODS html file="\\cchd.org\odsdfs$\ODSShared\Surveillance Reports and QA\Surveillance QA\&AGENCY..html" style=Seaside;
ODS title "Contact FR-QC" ;
ods escapechar = "~";
OPTIONS NODATE NONUMBER;
option orientation=landscape;
proc report data=TEST nofs center;
where AGENCY="&AGENCY";
columns AGENCY SCORE;
run;
ODS html CLOSE;
%MEND CAR;%CAR (AGENCY=A); /*Report for Agency A*/
The Agency list is dynamic and I want to generate the report by agency by looping the observations listed in AGENCY... Any insight is appreciated.
Although you can loop, I'm a fan of the CALL EXECUTE approach since it seems a bit cleaner to me.
Here's an example of that, you can run it to test. Its broken into small steps so you can follow it, but feel free to combine them into one once you understand the concept.
Same idea, except printing a report for each age, sex combination in the SASHELP.CLASS table.
Thank you.. Call Execute does magic!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.