BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
P5C768
Obsidian | Level 7

I'm using the following code to PDF a GMAP procedure and I'm having multiple problems.  First, my title doesn't show up in the PDF, only in the HTML.  Second, I would like to repeat this procedure to include multiple maps in one document (I'm thinking of proc document using the move>to statement, but I'm not sure how to reference the individual maps).  Any help is greatly appreciated.  Thanks.

goptions reset=all cback=white htitle=14pt htext=10pt hsize=4in vsize=4in;

options GSTYLE;

pattern1 v=ms c=VLIGB;

pattern2 v=ms c=LIGB;

pattern3 v=ms c=STGB;

pattern4 v=ms c=BIGB;

pattern5 v=ms c=VIGB;

legend1

across=6

shape=bar(3,4)pct

position= (middle bottom outside)

label=("Percent" Position=(center top));

title 'My Title';

proc gmap

  map=Proj

  data=Proj;

  id maparea;

  choro Change_Group / levels=6 legend=legend1;

run;

quit;

ods pdf file="Map.pdf"  style=analysis  pdftoc=2;

ods pdf close;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  Generally, your ODS "sandwich" surrounds the code you want to write to your destination. By default, if you are using SAS Display Manager, in SAS 9.3, ODS HTML is turned ON by default. I would normally expect to see something like this:

ODS _ALL_ CLOSE; /* close all open destinations */

 

** 1) simple invocation;

ods pdf file="Map.pdf"  style=analysis  pdftoc=2;

...your SAS Graph code here....

ods pdf close;

  

If you are running SAS 9.3, then you can use the GTITLE or NOGTITLE options with ODS PDF to control where the title goes. For example, in the code examples below, I turned on the BORDER goption, so you could see the impact of GTITLE or NOGTITLE. In #1 output, with NOGTITLE, the SAS title is "outside" the border; but with GTITLE option, the SAS title is "inside" the border. I know it's not a very interesting image, but the point is to see SAS TITLE behavior.

ODS _ALL_ CLOSE; /* close all open destinations */

 

options nodate nonumber;

goptions border;

ods pdf file='c:\temp\gplot_examp1.pdf' nogtitle notoc;

proc gplot data=sashelp.class;

  title '1) GPLOT Example with NOGTITLE';

  title2 'Title is "outside" graph image border';

  plot height*age=sex /

       description='Plot'

       hminor=0;

run;

quit;

ods pdf close;

 

options nodate nonumber;

goptions border;

ods pdf file='c:\temp\gplot_examp2.pdf' gtitle notoc;

proc gplot data=sashelp.class;

  title '2) GPLOT Example with GTITLE';

  title2 'Title is "inside" graph image border';

  plot height*age=sex /

       description='Plot'

       hminor=0;

run;

quit;

ods pdf close;

I'm not sure what you mean when you say that you want to "create multiple maps in one document" -- normally all your code within one "sandwich" will get written to the open destination. So you could have this type of code and all your outputs would be put into the named PDF from your FILE= option:

 

ods pdf file="Map2.pdf"  style=analysis  pdftoc=2;

...first map step....

...second map step...

...some other procedure step...

...another map step...

ods pdf close;

So you may not need to go down the ODS DOCUMENT road if all you want to do is get multiple SAS/GRAPH outputs into 1 PDF file. You can prove this to yourself by running this code. Again, it's not GMAP output -- but GMAP would work the same way.

  

options nodate nonumber orientation=landscape;

goptions reset=all;

ods pdf file='c:\temp\two_in_one_examp.pdf' nogtitle notoc;

proc gchart data=sashelp.class;

  title '3a) Gchart Example with SASHELP.CLASS';

  vbar age / discrete

             sumvar=height type=mean

             patternid=midpoint;

run;

quit;

 

proc gchart data=sashelp.prdsale;

  title '3b) Gchart Example with SASHELP.PRDSALE';

  vbar product / sumvar=actual type=mean

                 patternid=midpoint;

run;

quit;

ods pdf close;

However, if you do want to use ODS DOCUMENT and PROC DOCUMENT to do your replay, there are Tech Support notes (36505 - Organizing output based on BY variable values: PROC DOCUMENT or Macro or 34626 - How to rearrange tables using PROC DOCUMENT) that will help you. To find out the names of the objects that you have saved into the document store, you would use PROC DOCUMENT with the LIST statement, as shown in the notes.

An alternative to using ODS DOCUMENT/PROC DOCUMENT is to also investigate using PROC GREPLAY (24942 - Use PROC GREPLAY to dynamically replay GCHART and GPLOT output on the same page or 48546 - Use PROC GREPLAY to simplify the table of contents when writing graphics output to a PDF fil... ).

cynthia

View solution in original post

6 REPLIES 6
Cynthia_sas
SAS Super FREQ

Hi:

  Generally, your ODS "sandwich" surrounds the code you want to write to your destination. By default, if you are using SAS Display Manager, in SAS 9.3, ODS HTML is turned ON by default. I would normally expect to see something like this:

ODS _ALL_ CLOSE; /* close all open destinations */

 

** 1) simple invocation;

ods pdf file="Map.pdf"  style=analysis  pdftoc=2;

...your SAS Graph code here....

ods pdf close;

  

If you are running SAS 9.3, then you can use the GTITLE or NOGTITLE options with ODS PDF to control where the title goes. For example, in the code examples below, I turned on the BORDER goption, so you could see the impact of GTITLE or NOGTITLE. In #1 output, with NOGTITLE, the SAS title is "outside" the border; but with GTITLE option, the SAS title is "inside" the border. I know it's not a very interesting image, but the point is to see SAS TITLE behavior.

ODS _ALL_ CLOSE; /* close all open destinations */

 

options nodate nonumber;

goptions border;

ods pdf file='c:\temp\gplot_examp1.pdf' nogtitle notoc;

proc gplot data=sashelp.class;

  title '1) GPLOT Example with NOGTITLE';

  title2 'Title is "outside" graph image border';

  plot height*age=sex /

       description='Plot'

       hminor=0;

run;

quit;

ods pdf close;

 

options nodate nonumber;

goptions border;

ods pdf file='c:\temp\gplot_examp2.pdf' gtitle notoc;

proc gplot data=sashelp.class;

  title '2) GPLOT Example with GTITLE';

  title2 'Title is "inside" graph image border';

  plot height*age=sex /

       description='Plot'

       hminor=0;

run;

quit;

ods pdf close;

I'm not sure what you mean when you say that you want to "create multiple maps in one document" -- normally all your code within one "sandwich" will get written to the open destination. So you could have this type of code and all your outputs would be put into the named PDF from your FILE= option:

 

ods pdf file="Map2.pdf"  style=analysis  pdftoc=2;

...first map step....

...second map step...

...some other procedure step...

...another map step...

ods pdf close;

So you may not need to go down the ODS DOCUMENT road if all you want to do is get multiple SAS/GRAPH outputs into 1 PDF file. You can prove this to yourself by running this code. Again, it's not GMAP output -- but GMAP would work the same way.

  

options nodate nonumber orientation=landscape;

goptions reset=all;

ods pdf file='c:\temp\two_in_one_examp.pdf' nogtitle notoc;

proc gchart data=sashelp.class;

  title '3a) Gchart Example with SASHELP.CLASS';

  vbar age / discrete

             sumvar=height type=mean

             patternid=midpoint;

run;

quit;

 

proc gchart data=sashelp.prdsale;

  title '3b) Gchart Example with SASHELP.PRDSALE';

  vbar product / sumvar=actual type=mean

                 patternid=midpoint;

run;

quit;

ods pdf close;

However, if you do want to use ODS DOCUMENT and PROC DOCUMENT to do your replay, there are Tech Support notes (36505 - Organizing output based on BY variable values: PROC DOCUMENT or Macro or 34626 - How to rearrange tables using PROC DOCUMENT) that will help you. To find out the names of the objects that you have saved into the document store, you would use PROC DOCUMENT with the LIST statement, as shown in the notes.

An alternative to using ODS DOCUMENT/PROC DOCUMENT is to also investigate using PROC GREPLAY (24942 - Use PROC GREPLAY to dynamically replay GCHART and GPLOT output on the same page or 48546 - Use PROC GREPLAY to simplify the table of contents when writing graphics output to a PDF fil... ).

cynthia

P5C768
Obsidian | Level 7

Thanks, Cynthia, that worked perfectly.  One further question, when I use a similar process to combine numerous proc reports into one PDF, I use the "contents=" statement to set the text that will be displayed in the PDF.  Is there a way to do that in the GMAP or Document procedure, so that the output doesn't say "Choropleth Map of..." and "The GMAP Procedure?"  Thanks again.

Cynthia_sas
SAS Super FREQ


Hi:

  CONTENTS= is only an option for PROC PRINT, PROC REPORT and PROC TABULATE (and PROC FREQ multi-way tables). It does not work with graph procedures. You should be able to use NAME= and DESCRIPTION= on your action statement (like the CHORO statement). The doc is here: SAS/GRAPH(R) 9.3: Reference, Third Edition for the CHORO statement.

  The NAME= value will be what you see in the GRSEG entry and, if you do make an ODS DOCUMENT, the NAME= value will be used to contruct the object name in the document store. So, if you had NAME='Mymap' in the code, the DOCUMENT object name will be something like:

\Gmap#1\Mymap1#1

and then the DESCRIPTION= value would be the label used in the DOCUMENT store. DESCRIPTION= will get rid of "Choropleth Map of..." in the SAS Results window and the PDF TOC.

  But, using NAME= and DESCRIPTION= will not get rid of the top level node that says "The GMAP Procedure" in the PDF table of contents. You would have to use ODS DOCUMENT to get rid of or rename the top level node. The Tech Support notes that I posted show how to change the node labels with PROC DOCUMENT syntax.

cynthia

P5C768
Obsidian | Level 7

Thanks Cynthia, I believe the DESCRIPTION= is what I was looking for.  I have noticed though that is I run the ODS PDF without exiting out of SAS, it appears the DOCUMENT object continues to add maps and directories.  For example, the first time I run the code, it works perfectly, but the next time instead of having 2 maps for the 2 GMAP statements I am using, I have 4.  Then 6, then 8 and so on.  Is there a way to clear the prior results at run time?  I have tried using ods PDF newfile=proc; with no results.  Thanks again for all your help!

Cynthia_sas
SAS Super FREQ

Hi:

You have 2 separate, but similar challenges:

1) your SAS/GRAPH job makes a GSEG entry EVERY time you run your code. It names the entries EVERY time by tacking a number onto the default name or whatever you specify for NAME=. So, a good practice is to close the GRAPH1 window and delete the GSEG entries before each run;

2) When you create your ODS DOCUMENT store, you should create it with an access of WRITE (not UPDATE), so that the DOCUMENT store will be overwritten and created new each time.

  But philosophically, I probably wouldn't create the ODS DOCUMENT store -- every time you create the SAS/GRAPH output-- until the very, very, very end step in the process. I would get the graphs all working and then add the ODS DOCUMENT store syntax, with the appropriate "housekeeping" statements to make sure that the final job only runs once and creates the names that you need to have in the DOCUMENT store. Or else, if you need multiple graphs and multiple document stores, I would change the names, possibly with macro variables each time your job runs.

  This Tech Support note shows you how to delete GSEG entries: 13045 - Unable to delete GRSEG entries from a graphics catalog using the displaymanager Results wind...

If you take care of the GSEG entries, then when you do make the document store (using WRITE access) you should have only the most current entries stored in the document store.

cynthia

ballardw
Super User

If you are careful you may find using the GOPTION GOUTMODE=REPLACE may be helpful. It helps to specify the GOUT catalog(s) in the graphic procedures and then specify the names. If everything starts empty the first time as you test the named items are replaced instead of continually incremented. Use a different NAME=for each call to a graphics procedure and watch the limits in length for names. If any are using by groups to create graphs then the name will be incremented and if you don't make the name short enough it may be difficult to sort out generated names. When I was spending lots of time with GREPLAY I usually used names of 6 or fewer characters to allow for the names to be numbered as I expected.

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!

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.

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
  • 6 replies
  • 5249 views
  • 4 likes
  • 3 in conversation