BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?

Thanks for any help!
10 REPLIES 10
Bill
Quartz | Level 8
Code based automated is absolutely possible with SAS!


ods pdf file="c:\Directory\filename.pdf"
author='your name';


proc gslide;

note h=5 j=c c='cx969696' 'Weekly';
note h=5 j=c c='cx969696' 'Usage';
note h=5 j=c c='cx969696' 'Report';
note h=5;
note h=2 j=c c='cx969696' "&start to &end";

run;
quit;

ods pdf close;
deleted_user
Not applicable
Thanks for the tip, Bill.

I'm getting an error (and no PDF output) when I run this.

Here it is:

ERROR 22-322: Syntax error, expecting one of the following: ;, ANCHOR, AUTHOR, BACKGROUND, BASE, BODY, BOOKMARK, BOOKMARKGEN, BOOKMARKLIST, CLOSE, COLOR, COLUMNS, CONTENTS, DISPLAY, FILE, FONTSCALE, HOST, IMAGE_DPI, KEYWORDS, NAMED_DEST, NEWFILE, NOBACKGROUND, NOBOOKMARKGEN, NOBOOKMARKLIST, NOCOLOR, NOCONTENTS, NOPDFNOTE, NOTOC, PCL, PDF, PDFMARK, PDFNOTE, PRINTER, PS, SAS, STARTPAGE, STYLE, SUBJECT, TEXT, TITLE, UNIFORM.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

I edited the commands by taking out the note lines (they were red and I wasn't sure what they did...total newby!) as below. I put the code in just before the gplot code. What am I doing wrong?

ods pdf file="C:\Documents and Settings\*****\Desktop\0x1.pdf"

proc gslide;

/*note h=5 j=c c='cx969696' 'Weekly';
note h=5 j=c c='cx969696' 'Usage';
note h=5 j=c c='cx969696' 'Report';
note h=5;
note h=2 j=c c='cx969696' "&start to &end";*/

run;
quit;

ods pdf close;
Cynthia_sas
SAS Super FREQ
Hi:
I suggest a different approach.

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 &REG in the macro program and substitute whatever the current value of REG is for &REG. So in effect, when I program, &REG 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.

[pre]

%let FReg = %sysfunc(compress(&Reg,/));
%let FReg = %sysfunc(compress(&FReg));

[/pre]

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:
[pre]

ods pdf file="&FReg..pdf" style=statdoc;

[/pre]

Next, I have a PROC SORT that will get a subset of 1 region's obs from SASHELP.SHOES like this:
[pre]
proc sort data=sashelp.shoes out=shoes;
by region subsidiary product;
where upcase(Region) = "????????";
run;
[/pre]

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 &REG as united states or UnItEd StaTeS. So, &REG 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 &REG 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:
[pre]

proc sort data=sashelp.shoes out=shoes;
by region subsidiary product;
where upcase(Region) = "%upcase(&Reg)";
run;

[/pre]

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:
[pre]
** invoke the macro program;
%RegRept(Reg=united states);
%RegRept(Reg=Pacific);
%RegRept();
%RegRept(Reg=Central america/caribbean);

[/pre]


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 &REG.

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.

cynthia

[pre]
%global Reg FReg;

%macro RegRept(Reg=Canada);
** Get rid of spaces and slashes.;

%let FReg = %sysfunc(compress(&Reg,/));
%let FReg = %sysfunc(compress(&FReg));

proc sort data=sashelp.shoes out=shoes;
by region subsidiary product;
where upcase(Region) = "%upcase(&Reg)";
run;

options center missing=' ' orientation=landscape;

ods listing close;
ods pdf file="&FReg..pdf" style=statdoc;

goptions reset=all device=actximg;
axis1 minor=none label=("Subsidiary") ;
axis2 minor=none label=("Avg Sales") ;

proc gchart data=shoes;
title "&Reg: Product Sales by Subsidiary";
vbar3d Subsidiary /
sumvar=sales type=mean
name="Ssal"
subgroup=Product
maxis=axis1
raxis=axis2;
run;
quit;

ods pdf close;
options missing=.;
title;

%mend RegRept;

** invoke the macro program;
%RegRept(Reg=united states);
%RegRept(Reg=Pacific);
%RegRept();
%RegRept(Reg=Central america/caribbean);

[/pre]
deleted_user
Not applicable
Cynthia,

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.

Any tips on doing this?

Thanks again for your help.
Cynthia_sas
SAS Super FREQ
Hi:
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.

cynthia
deleted_user
Not applicable
Cynthia,

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.

Thanks for your help.
Bill
Quartz | Level 8
Robb;

I'll give you another simple example that works on PC SAS9.1

ods pdf file="c:\temp\test.pdf";

goptions reset=all
device=sasprtc;

proc gchart data=sashelp.class;
hbar age;
run;
quit;

ods pdf close;

Give it a try.
dbravo
SAS Employee
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.
deleted_user
Not applicable
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.

Thanks again for all your help!
deleted_user
Not applicable
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

PeterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10 replies
  • 1190 views
  • 0 likes
  • 4 in conversation