BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mariko5797
Pyrite | Level 9

I want to loop through all the subject IDs and output a png file for each subject. The run time is fairly short and nothing is being outputted. Is there some sort of statement I am missing? No errors or warnings appear.

data test;
 input usubjid $ day mldapcrp mldapcrr psrvqres psrvres fillc @@;
 cards;
 VMP.1	5	6.8	1	7.9	1	1
 VMP.1	6	9.7	1	.	0	2
 VMP.1	7	.	0	8.4	1	3
 VMP.1	8	.	0	.	.	.
 VMP.1	9	.	0	.	0	.
 VMP.1	10	4.3	1	.	0	2
 VMP.2	5	7.3	1	7.9	1	1
 VMP.2	6	4.1	1	.	.	2
 VMP.2	7	3.2	1	6.7	1	1
 VMP.2	8	.	.	.	0	.
 VMP.2	9	.	0	8.3	1	3
 VMP.2	10	5.5	1	.	0	2
 ;
run;

%macro figure();
	ods listing gpath= "&&rptdir.\";
	title; footnote;
	ods escapechar= '^';
	ods graphics on;
	ods graphics / reset= index imagename= "Fig_&id." imagefmt= png;	
	footnote j=c h=12pt bold f= "times new roman" color=red "CONFIDENTIAL";
	title j= center h= 12pt f= "times new roman" bold c= black "&&title. VMP.&id.";

	proc sgplot data= final(where= (usubjid = "VMP.&id."));
	 vbarparm category= day response= fillc / barwidth= 1 colorresponse= fillc
	 	colormodel= (purple red blue) transparency= 0.3 name= 'shade';
	 series x= day y= mldapcrp / legendlabel= "Result 1t" name= "v1" lineattrs= (pattern= 4) y2axis;
	 series x= day y= psrvqres / legendlabel= "Result 2" name= "v2";
	 yaxis label= "Label Y1";
	 y2axis label= "Label Y2";
	 xaxis label= "Study Day";
	 keylegend  / exclude= ("shade");
	run;
 ods graphics off;
%mend figure;

proc sql noprint;
 select distinct usubjid into: idlist separated by ' '
 	from test;
quit;

%put &=idlist;

%macro callreport;
	%do x= 1 %to %sysfunc(countw(&idlist));
	%let id = %scan(&idlist, &x);
	%figure;
	%end;
%mend callreport;

%let title= %str(Comparison, Subject);
%callreport;

Log

NOTE: PROCEDURE SGPLOT used (Total process time):
      real time           0.01 seconds
      cpu time            0.03 seconds

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@mariko5797 

You can create file names that have the ID in the file name, and you can create titles that have the ID in the title, all by using a BY statement.

 

Here is documentation on IMAGENAME=

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p0kroq43yu0lspn16hk1u4c65lti.htm#n...

 

Similarly, the ID can be part of the TITLE when you use by statements

https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lestmtsglobal/p10gcmrmf83iaxn1ilrx4pra969n.htm#n1...

 

So, again, I think macros are not needed, and the whole thing can be programmed using BY statements.

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Before I try to debug your macro, I point out that it seems as if using a BY statement in your PROC SGPLOT would do what you want without macros. So, please try it with a BY statement in PROC SGPLOT and without a macro.

--
Paige Miller
mariko5797
Pyrite | Level 9

The by statement does output a figure for each id, but is there a way to get it to display each id it is outputting and save it in the file name with this method?

Reeza
Super User

The code refers to final and test datasets but only include test.

There are two && in front of rptdir macro variable.

GPATH setting doesn't work properly for me, but I'm using SAS Studio where listing is not the default output. Assuming it works for you.

 

Tested, this should work, assuming GPATH is fixed.

 

data final;
infile cards dlm='09'x;
 input usubjid $ day mldapcrp mldapcrr psrvqres psrvres fillc;
 cards;
 VMP.1	5	6.8	1	7.9	1	1
 VMP.1	6	9.7	1	.	0	2
 VMP.1	7	.	0	8.4	1	3
 VMP.1	8	.	0	.	.	.
 VMP.1	9	.	0	.	0	.
 VMP.1	10	4.3	1	.	0	2
 VMP.2	5	7.3	1	7.9	1	1
 VMP.2	6	4.1	1	.	.	2
 VMP.2	7	3.2	1	6.7	1	1
 VMP.2	8	.	.	.	0	.
 VMP.2	9	.	0	8.3	1	3
 VMP.2	10	5.5	1	.	0	2
 ;
run;


%let rptdir = '/home/fkhurshed/Demo1';

 
%macro figure(id);
	ods listing gpath= "&rptdir./";
	title; footnote;
	ods escapechar= '^';
	ods graphics on;
	ods graphics / reset= index imagename= "Fig_&id." imagefmt= png;	
	footnote j=c h=12pt bold f= "times new roman" color=red "CONFIDENTIAL";
	title j= center h= 12pt f= "times new roman" bold c= black "&&title. VMP.&id.";

	proc sgplot data= final(where= (usubjid = "VMP.&id."));
	 vbarparm category= day response= fillc / barwidth= 1 colorresponse= fillc
	 	colormodel= (purple red blue) transparency= 0.3 name= 'shade';
	 series x= day y= mldapcrp / legendlabel= "Result 1t" name= "v1" lineattrs= (pattern= 4) y2axis;
	 series x= day y= psrvqres / legendlabel= "Result 2" name= "v2";
	 yaxis label= "Label Y1";
	 y2axis label= "Label Y2";
	 xaxis label= "Study Day";
	 keylegend  / exclude= ("shade");
	run;
 ods graphics off;
%mend figure;

proc sql noprint;
 select distinct usubjid into: idlist separated by ' '
 	from final;
quit;

%put &=idlist;

%macro callreport;
	%do x= 1 %to %sysfunc(countw(&idlist));
	%let id = %scan(&idlist, &x);
	%figure(&id);
	%end;
%mend callreport;

%let title= %str(Comparison, Subject);
%callreport;
PaigeMiller
Diamond | Level 26

@mariko5797 

You can create file names that have the ID in the file name, and you can create titles that have the ID in the title, all by using a BY statement.

 

Here is documentation on IMAGENAME=

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p0kroq43yu0lspn16hk1u4c65lti.htm#n...

 

Similarly, the ID can be part of the TITLE when you use by statements

https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lestmtsglobal/p10gcmrmf83iaxn1ilrx4pra969n.htm#n1...

 

So, again, I think macros are not needed, and the whole thing can be programmed using BY statements.

--
Paige Miller
Reeza
Super User
data test;
 input usubjid $ day mldapcrp mldapcrr psrvqres psrvres fillc @@;
 cards;
 VMP.1	5	6.8	1	7.9	1	1
 VMP.1	6	9.7	1	.	0	2
 VMP.1	7	.	0	8.4	1	3
 VMP.1	8	.	0	.	.	.
 VMP.1	9	.	0	.	0	.
 VMP.1	10	4.3	1	.	0	2
 VMP.2	5	7.3	1	7.9	1	1
 VMP.2	6	4.1	1	.	.	2
 VMP.2	7	3.2	1	6.7	1	1
 VMP.2	8	.	.	.	0	.
 VMP.2	9	.	0	8.3	1	3
 VMP.2	10	5.5	1	.	0	2
 ;
run;

%macro figure(id);
	ods listing gpath= "&&rptdir.\";
	title; footnote;
	ods escapechar= '^';
	ods graphics on;
	ods graphics / reset= index imagename= "Fig_&id." imagefmt= png;	
	footnote j=c h=12pt bold f= "times new roman" color=red "CONFIDENTIAL";
	title j= center h= 12pt f= "times new roman" bold c= black "&&title. VMP.&id.";

	proc sgplot data= final(where= (usubjid = "VMP.&id."));
	 vbarparm category= day response= fillc / barwidth= 1 colorresponse= fillc
	 	colormodel= (purple red blue) transparency= 0.3 name= 'shade';
	 series x= day y= mldapcrp / legendlabel= "Result 1t" name= "v1" lineattrs= (pattern= 4) y2axis;
	 series x= day y= psrvqres / legendlabel= "Result 2" name= "v2";
	 yaxis label= "Label Y1";
	 y2axis label= "Label Y2";
	 xaxis label= "Study Day";
	 keylegend  / exclude= ("shade");
	run;
 ods graphics off;
%mend figure;

proc sql noprint;
 select distinct usubjid into: idlist separated by ' '
 	from test;
quit;

%put &=idlist;

%macro callreport;
	%do x= 1 %to %sysfunc(countw(&idlist));
	%let id = %scan(&idlist, &x);
	%figure(&id);
	%end;
%mend callreport;

%let title= %str(Comparison, Subject);
%callreport;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1218 views
  • 2 likes
  • 3 in conversation