Hello!
I'm creating a .pdf document which consists of several outputs gruped by a "group by" and I need the reporting for each group to be in a single file, i.e. all output in group=1 in the same file and the same for the rest of the groups. I don't know how to gather all output from different proc's but the same group in the same pdf. I am now getting a different .pdf per proc.
Can anyone help me?
Thanks!!
/*Input table creation*/
data tas;
drop div;
do group_var=1,2;
if group_var=1 then do;
div=4;alp=0.05;
end;
else do;
div=0.5;alp=0.01;
end;
do x=1 to 3;
y=x+ranuni(3)/div;output;
y=x+ranuni(3)/div;output;
end;end;
run;
/*Reporting*/
%let pdfFile=...\pruebaRep.pdf;
ods listing off;
ods pdf file="&pdfFile." newfile=bygroup;
ods graphics on;
proc corr data=tas;
var x y;
BY GROUP_VAR;
run;
proc sgplot data=tas;
scatter x=x y=y / markerattrs=(symbol=circle size=2 mm);
BY GROUP_VAR;
run;
ods _all_ close;
ods listing;
Unfortunately in these cases you cannot use BY group processing, you need macro logic or automatic code generation of some kind.
I wrote a tutorial on how to do this here:
https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md
If you have questions or feedback please let me know.
I highly recommend following the code in the tutorial first and then doing yours step by step.
@CarlosP73 wrote:
Hello!
I'm creating a .pdf document which consists of several outputs gruped by a "group by" and I need the reporting for each group to be in a single file, i.e. all output in group=1 in the same file and the same for the rest of the groups. I don't know how to gather all output from different proc's but the same group in the same pdf. I am now getting a different .pdf per proc.
Can anyone help me?
Thanks!!
/*Input table creation*/
data tas;
drop div;
do group_var=1,2;
if group_var=1 then do;
div=4;alp=0.05;end;
else do;
div=0.5;alp=0.01;
end;
do x=1 to 3;
y=x+ranuni(3)/div;output;
y=x+ranuni(3)/div;output;
end;end;
run;
/*Reporting*/
%let pdfFile=...\pruebaRep.pdf;
ods listing off;
ods pdf file="&pdfFile." newfile=bygroup;
ods graphics on;
proc corr data=tas;
var x y;
BY GROUP_VAR;
run;proc sgplot data=tas;
scatter x=x y=y / markerattrs=(symbol=circle size=2 mm);
BY GROUP_VAR;
run;
ods _all_ close;
ods listing;
Hello Reeza,
Thank you for your answer. Unfortunately I still cannot find a way, even using macro language, to stop and resume generation of ooutput in an ods pdf within the very same group group.
What I'm trying now is the use of ods pdf(id=) to select or exclude output. The following SAS document can be of help:
https://www.lexjansen.com/nesug/nesug12/gr/gr04.pdf
This is the code:
data tas;drop div;
do group_var=1,2;
if group_var=1 then do;
div=4;
alp=0.05;
end;
else do;
div=0.5;
alp=0.01;
end;
do x=1 to 3;
y=x+ranuni(3)/div;
output;
y=x+ranuni(3)/div;
output;
end;
end;
run;
filename regoutP1 '...\pruebaRepG1.pdf';
filename regoutP2 '...\Desktop\pruebaRepG2.pdf';
ods _all_ close;
ods pdf(id=group1) file=regoutP1;
ods pdf(id=group2) file=regoutP2;
ods pdf(id=group1) select all;
ods pdf(id=group2) exclude all;
proc corr data=tas(where=(group_var=1));
var x y;
run;
proc sgplot data=tas(where=(group_var=1));
scatter x=x y=y / markerattrs=(symbol=circle size=2 mm);
run;
ods pdf(id=group1) exclude all;
ods pdf(id=group2) select all;
proc corr data=tas(where=(group_var=2));
var x y;
run;
proc sgplot data=tas(where=(group_var=2));
scatter x=x y=y / markerattrs=(symbol=circle size=2 mm);
run;
ods _all_ close;
ods listing;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: