BookmarkSubscribeRSS Feed
Tamino
Obsidian | Level 7

Hi

 

I am currenly transferring my results into graphs with SAS, but I am struggling with formatting and exporting them in a way they are readable in a document. I have following command to create the graphs (not mine, got it from a template):

 

proc sgplot data=mydata noautolegend;
band x=date upper=band1_u lower=band1_l / noextend;
band x=date upper=band2_u lower=band2_l / noextend;
scatter x=date y=yvalues /  markerattrs=(symbol=circlefilled color=CX203554 size=4) name="Observed rate";
series x=date y=modeled1 / lineattrs=(pattern=solid color=CX536582 thickness=2) name="Modeled trend";
series x=date y=modeled2 / lineattrs=(pattern=solid color=CX536582 thickness=2) name="none";
series x=date y=projection / lineattrs=(pattern=shortdash color=/*CX536582*/black thickness=2) name="Predicted trend";

yaxis label="Y Axis" values=(0 to 15000 by 1500) labelattrs=(size=15) valueattrs=(size=13);
xaxis label="Timeline" labelattrs=(size=18) valueattrs=(size=13) interval=month;
refline '1Jan2015'd '1Jan2016'd '1Jan2017'd '1Jan2018'd '1Jan2019'd '1Jan2020'd '1Jan2021'd / axis=x;
keylegend "Observed proportion" "Modeled trend"  "Predicted trend" / location=inside position=topright across=1 opaque;
run;

This leads to following graph:

SGPlot_SAS.png

 

1. How can I adjust the letter size of "Modeled trend" and "Predicted trend"? They are barely readable when putting them in a document.

 

2. How can I export the graph afterwards directly from SAS into a folder in good quality (.jpeg, .pdf or else)?

 

3. Maybe any other suggestions to nicely display the graph?

 

Thank you very much!

6 REPLIES 6
Ksharp
Super User
*the path/folder to store the graph And image_dpi=300  make better quality graph;
ods listing gpath='c:\temp' image_dpi=300 ;  
ods graphics/outputfmt=png imagename='want';
proc sgplot data=sashelp.class;
scatter x=weight y=height/group=sex datalabel=name;
keylegend /location=inside position=nw valueattrs=(size=30) titleattrs=(size=30);
run;

Ksharp_0-1688646879696.png

Ksharp_1-1688646914212.png

 

Tamino
Obsidian | Level 7

Thank you, the export works with this command. But actually the saved image looks different as displayed in SAS sometimes. For example the labeling of the x-axis is not the same in SAS and in the saved image.

Ksharp
Super User
Then post your code and dataset and picture to illustrate your problem ?
Tamino
Obsidian | Level 7

Hi

I am currenly transferring my results into graphs with SAS, but I am struggling with formatting them in a way they are readable in a document. I have following command to create the graphs (not mine, got it from a template):

 

proc sgplot data=mydata noautolegend;
band x=date upper=band1_u lower=band1_l / noextend;
band x=date upper=band2_u lower=band2_l / noextend;
scatter x=date y=yvalues /  markerattrs=(symbol=circlefilled color=CX203554 size=4) name="Observed rate";
series x=date y=modeled1 / lineattrs=(pattern=solid color=CX536582 thickness=2) name="Modeled trend";
series x=date y=modeled2 / lineattrs=(pattern=solid color=CX536582 thickness=2) name="none";
series x=date y=projection / lineattrs=(pattern=shortdash color=/*CX536582*/black thickness=2) name="Predicted trend";

yaxis label="Y Axis" values=(0 to 15000 by 1500) labelattrs=(size=15) valueattrs=(size=13);
xaxis label="Timeline" labelattrs=(size=18) valueattrs=(size=13) interval=month;
refline '1Jan2015'd '1Jan2016'd '1Jan2017'd '1Jan2018'd '1Jan2019'd '1Jan2020'd '1Jan2021'd / axis=x;
keylegend "Observed proportion" "Modeled trend"  "Predicted trend" / location=inside position=topright across=1 opaque;
run;

This leads to following graph:

Tamino_0-1689076104771.png

 

 

1. How can I adjust the letter size of "Modeled trend" and "Predicted trend"? They are barely readable when putting them in a document.

 

2. How can I rotate the labelling of the x-axis 45 degrees (from bottom left to up right)?

 

3. Maybe any other suggestions to nicely display the graph?

 

Thank you very much!

Ksharp
Super User

Here is for your second question.

proc sgplot data=sashelp.class;
scatter x=weight y=height/group=sex datalabel=name;
keylegend /location=inside position=nw valueattrs=(size=30) titleattrs=(size=30);

xaxis fitpolicy=rotatealways valuesrotate=DIAGONAL2;
run;

Ksharp_0-1689077516522.png

 

ballardw
Super User

Some generic comments about output and documents.

First thing is the ODS Style in effect. When you use ODS to different destinations, such as RTF or PDF then the ODS STYLE used by default may well differ from the typical results window results. So you may want to specify the STYLE= option on the ODS destination statement to make sure that it is using the same setting for output as you used when creating the graphs. Otherwise colors, marker types, and even line settings may change.

 

Some of your ODS destinations such as RTF and PDF will honor a PAPERSIZE option to create custom size display areas. Otherwise they default to your system page defaults.

 

ODS RTF also has options GTITLE/NOGTITLE and GFOOTNOTE/NOGFOOTNOTE. If want to use word processor tools to include the titles and/or footnotes that may appear in graphs as part of a list of figures or such then you may want to specify the NOGTITLE/NOGFOOTNOTE option to make them part of the RTF output instead of in the graph image.

 

ODS Graphics options let you change the height/width of the graph display area but if you specify a size that the ODS destination can't currently use because it won't fit on the logical paper size then results are problematic. Additionally the ODS Graphics may scale fonts to fit a custom image size that can make them larger/smaller than desired. So you may want to investigate behavior of SCALE/NOSCALE on ODS Graphics with your particular graphs.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 899 views
  • 2 likes
  • 3 in conversation