BookmarkSubscribeRSS Feed
rab24
Calcite | Level 5
I am using EG3 to create a large series of graphs of which I only need some. Rather than 1 complete PDF with all graphs, is there a way I can automate production of these graphs into separate PDF files that have file names generated by the "group by" variables used in the graph code?

In essence, I have:

Myfile.pdf
Page 1) Tom graph
Page 2) Rob graph
Page 3) Jan graph

but I need:
Tom.pdf
Rob.pdf
Jan.pdf

Where Tom, Rob, and Jan are possible values in my Groub By variable.
1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi...if you use a code node in EG, you can "sort" of generate the separate PDF files. There's an upside and a downside. The upside is that if you use NEWFILE=BYGROUP, the files get created automatically. The downside is that you can only "sort of" control the name of the file. For example, with the attached code:
[pre]
proc sort data=sashelp.prdsale out=prdsale;
by division prodtype;
run;

options orientation=landscape topmargin=1in bottommargin=1in
rightmargin=1in leftmargin=1in nodate number pageno=1;
run;

ods pdf file="c:\temp\GRFBY1.pdf" newfile=bygroup;

GOPTIONS reset=all device=actximg;

PROC GCHART DATA=prdsale;
title 'The Graph Title';
VBAR3D region / SUMVAR=actual
GROUP=product
SHAPE=BLOCK
FRAME TYPE=SUM
PATTERNID=MIDPOINT;
BY division prodtype;
format actual dollar12.2;
RUN; QUIT;

ods _all_ close;
title;
footnote;
ods listing;

[/pre]

If the SAS dataset has 4 BY groups, then the PDF output files will be named: GRFBY1.PDF, GRFBY2.PDF, GRFBY3.PDF, GRFBY4.PDF -- which means you can control the "beginning" part of the name, but NEWFILE= option wants to number the output files by incrementing the right-most number in the starting file name by 1 for each BYGROUP (in this example). Of course, after the files were created in c:\temp, you could go and issue a RENAME to name them what you wanted.

Your only other alternative would be to "macroize" the program to produce a single BY group -- and then you can control the name of every BY group's file -- when you invoke the macro program for each group. And then you could call the files Tom.PDF, Rob.PDF and Jan.PDF. (or whatever else you wanted).

Good luck!
cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 1043 views
  • 0 likes
  • 2 in conversation