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

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.

 

 

HabAM
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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. 

https://gist.github.com/statgeek/beb97b1c6d4517dde3b2

View solution in original post

3 REPLIES 3
Reeza
Super User

You can create a list of the agencies using PROC SQL, and here's how you loop over such a list:

 

http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n1qvxz5u3uru7yn1nk7q64ohvwak.htm&docset...

 

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.

 

 


 

Reeza
Super User

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. 

https://gist.github.com/statgeek/beb97b1c6d4517dde3b2

HabAM
Quartz | Level 8

Thank you.. Call Execute does magic!

HabAM

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 952 views
  • 1 like
  • 2 in conversation