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!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.