I've got a proc gplot procedure that generates 120 graphs per research participant and would like to export them to .pdf files such that all 120 graphs are included in each .pdf file. In other words, I want to export all the graphs so that I get one pdf file for each participant, each containing all 120 graphs for that participant.
I wonder if there are two ways to do this, through either a point-and-click approach or a code-based automated method.
I haven't had any luck so far, but I'm a real novice with SAS. Any tips?
1) get the code working for the graphs you want (so 1 participant gets all 120 graphs) (without any macro -- but this will probably involve making a subset of data for that 1 participant alone)
2) read about SAS Macro processing
3) as you read about SAS Macro processing, run and study this macro program and read my commentary
4) then see if you can adapt this program for your requirements
First, this program (at the end of the post) is a huge bunch o' code that is a SAS program bounded by the %MACRO and %MEND statements. Those statements tell SAS to compile a "boilerplate" version of my program statements. Every place in the program that you see a & or % in the code some kind of macro processing or macro variable substitution will take place.
Compiling the macro program is different from USING or invoking the macro program. The name of my macro program is: RegRept. It has one macro variable called 'REG' that it will need in order to be invoked correctly. If someone invokes the macro program without sending the program a value for REG, then the default value of Canada will be used.
When I define REG, I define it on the %MACRO statement. That tells the Macro facility to look for any references to ® in the macro program and substitute whatever the current value of REG is for ®. So in effect, when I program, ® becomes a placeholder for the "real" value that will be used when the macro facility actually sends code to SAS for execution.
But, of course, my data values for region are not just 1 word. And I want to use the region value in the PDF file name that I create for each region.
I know that the region names in SASHELP.SHOES can contain SPACES and in one case, has a slash (/)...so I don't want my filenames to have spaces or characters in them. That means the first thing I have to do is clean up or fix region.
These 2 %LET statments are making a new macro variable to fix the region value -- this lets the person who is invoking the macro pass in the region value as the y see the name in the data, but I use a fixed version of the name for the PDF file name.
The COMPRESS function is being used to take spaces and slashes out of the Region value. Any references to &FREG will result in the "fixed" region value being used. So, the file name for United States region will be: UnitedStates.pdf and the file name for Central America/Caribbean will be CentralAmericanCaribbean.pdf. In order to make SAS use this fixed value in my ODS PDF statement, I will USE &FREG like this:
ods pdf file="&FReg..pdf" style=statdoc;
Next, I have a PROC SORT that will get a subset of 1 region's obs from SASHELP.SHOES like this:
proc sort data=sashelp.shoes out=shoes;
by region subsidiary product;
where upcase(Region) = "????????";
Where I have the ??????, I have a challenge. In order to get a subset for just one REGION, I want to be able to build where statements like these:
where upcase(Region) = "UNITED STATES";
where upcase(Region) = "PACIFIC";
Somebody who's using my macro program, might enter a value for ® as united states or UnItEd StaTeS. So, ® would not be a good choice to use where the ?????? are. Since the values in the data set are stored as United States and Pacific (with initial caps) -- if I use incorrectly capitalized values for Region in the WHERE, I won't get any observations selected. I decide I'll uppercase Region in the comparison. That means I have to have an uppercased value on both sides of the equal sign.I use the UPCASE function on the variable from the dataset (Region) in my WHERE statement ... so I need to upcase the value of ® on the other side of the = sign. This WHERE statement specifies a data step function for the variable value and a macro function for the macro variable value:
proc sort data=sashelp.shoes out=shoes;
by region subsidiary product;
where upcase(Region) = "%upcase(&Reg)";
The SAS/Graph program that I have below only produces 1 graph for each region. The code points to the data file WORK.SHOES which will contain just 1 region's obs -- for one execution of the macro program. Where I have the single SAS/Graph program, you would have the code that generated 120 graphs for just ONE participant.
The macro program ends with %MEND -- this means that SAS can stop building the boilerplate program and put it into the WORK catalog where macros live until they're used. It's sort of like the putting a book on the shelf in the library. Just because I've CREATED a macro program, doesn't mean I want to use it right now. So the work catalog is a holding area for the macro program until I use it.
To use or invoke the macro program I have to use the macro program name (RegRept) in a special way: %RegRept(Reg=?????);
The % is a trigger that tells SAS to go to the macro catalog and check out the macro program for use. So I can invoke the macro program like this:
** invoke the macro program;
Notice that I was not careful when I was typing the region values in the invocation statement because I know that I've taken care of using them correctly in my macro program. (There are also ways to automatically create these statements or invoke the macro program automatically -- but those are MORE advanced macro topics.)
The invocation of %RegRept() -- is going to cause SAS to produce a report for Canada -- since that is the default value of ®.
There are other ways to code a solution to your question, including using a macro %DO loop (which is where the &start to &end post was going -- I think).
I know this is a long program, but careful study of macro processing and general SAS programming concepts can help you a LOT. You can also ask Tech Support for help if you get stuck figuring out how to change your SAS/Graph program to generate all 120 graphs for 1 participant or for help getting your macro program together.
%global Reg FReg;
** Get rid of spaces and slashes.;
I'll look into this Macro processing approach--thank you for your suggestion.
As I'm learning about this, however, I'm sure there's a point and click way to do this. A month ago, I was able to generate a pdf without having to code it, but I'm not sure how I did it. I'm sure I just stumbled upon it. Perhaps I used the print command (like print to pdf) to do it, but I'm not having any luck recreating whatever I did.
Were you working in SAS Enterprise Guide? Or some other interface/front end to SAS?
Print to PDF usually only works if you have some Adobe product installed on your machine. For example, I have the full Acrobat product on my machine, so no matter which application I'm in (Word, PowerPoint, SAS, Outlook, Browser) when I click PRINT in that application, I can always PRINT to PDF by choosing "Adobe PDF" from my available printer menu and then the print interface to Adobe starts Acrobat and prompts me for a PDF file name.
That's the only thing I can think of that would allow you to automatically PRINT to PDF from a PRINT menu. Inside Web Report Studio, there is an explicit way to create a PDF file from your Web Report Studio report.
You might consider contacting Tech Support with this question. I answered the question the way I did because most people who post to this forum are using code methods to create output files.
We do have the full version of Adobe on our server, but I've been unable to get it reproduce what it did the first time I used it. I very much appreciate your help with the code, and I'll be certain to make use of it. At this point, though, I'm going to continue trying to print manually rather than using code.
A (point and click) alternative is to generate the graphs and select File->Print. Uncheck the "Use SAS/Graph drivers" checkbox, select PDF as the printer name and check the "Print to file" checkbox. Select OK and you'll be prompted to name the PDF file. This can then be sent to all 120 participants.
Thanks for all the help, everyone. I managed to (finally!) create the pdf files. I'm not sure why I was having the problem that I was having, but I found the problem I was having with the point and click method. I'll try to explain, but my language for this may be confusing.
At the bottom of the SAS window, it seems to list something like an active folder. In my case, it was listing c:\windows\system32\0x1. I have no idea why it was doing that, perhaps because I was opening the code directly by double-clicking the saved code file?
I solved it by opening SAS directly, then copying and pasting the code from that file containing the code. It put my directory as c:\documents and settings\robb\eegdata, and voila--it worked, sort of. It generated a file called sasgraph.pdf each time I ran the code (which I did by find/replacing each of my participant numbers), and I just renamed that file to the appropriate participant number each time. A little inefficient, but it worked.
in response to "it was listing c:\windows\system32\0x1. I have no idea why it was doing that, perhaps because I was opening the code directly by double-clicking".
This is a feature of that operating system.
One alternative removes the need to open SAS directly.
Instead of double-click, use right-click and pick the pop-menu option "Batch Submit".
That runs the .sas program with the "current folder" set to the folder holding the program, rather than c:\windows\system32.
SAS Usage note describing the behaviour you found is at http://support.sas.com/kb/13/327.html