Skip to main content

Getting higher quality default graphs in SAS

Objective: I am running a statistical analysis in SAS, and the default ODS graphics look good, but I need them to be publication quality.

SAS can automatically create some nice graphs, and has greatly increased the availability of graphs within procedures.  If you like what you see, you might copy graphs directly from the SAS output window, or possibly you save graphs and output to a pdf or other external file format.  But this output will be low quality, generally 75 dpi.  Instead, add the following statements to write graphics directly to files, allowing control of format and quality.
ods graphics on /
      width=7in
      imagefmt=tiff
      imagemap=off
      imagename="MyPlot"
      border=off;

ods listing file="Body.rtf" style=journal gpath="."  dpi=600;

Once these statements have been submitted, all graphs created by subsequent procedures will be written  to files named MyPlotxx.tiff, where xx will be sequential numbers.  The tiff option can be changed to other formats, such as jpeg or png.  The dpi option controls the quality, with a typical graph file created by the above being around 38Meg, instead of the default 70 KB.  Use png to get a more reasonably sized graph (200KB) without the compression fuzziness of jpeg.  Gpath states where the files will be written, the dot here says use the current working directory (displayed in the lower right margin of the SAS window).  Note that tiff output is not supported by html or rtf ODS destinations, so listing is used.
To cancel these options, you need to reset the graphics options, and close the output file so the dpi option is removed (or set it to 100), for example
ods graphics on/reset;
ods listing close;
ods html ;
Another option used above, style=journal instead of the default style=htmlblue is an easy way to get black and white graphs.

Default configuration of SAS does not allow large graphs, so you are likely to get no graphs, and the following errors in SAS log:
WARNING: A very large output size of (4000, 3000) is in effect. This could make Java VM run out of memory and result in some Java exceptions. You should reduce the output size or DPI settings.
ERROR: Java virtual machine exception. java.lang.OutOfMemoryError: Java heap space.
To fix these, go to your config.sas file, usually located (Windows) in
     C:\Program Files\SASHome\SASFoundation\9.4\nls\en
Location varies depending on 32 vs 64 bit, the 9.4 version, and the en language.  The plain text file is sasv9.cfg, so use an editor like Notepad to find these lines
        -Xms128m
        -Xmx128m
and change them to
        -Xms1028m
        -Xmx1028m
Reload SAS to activate the changes, and dpi of at least 600 should be possible.

Example:  Run this SAS program to get low and high quality graphs.  If you zoom each graph, the low quality is clearly much fuzzier.

data one;
 label x="First Score"
  y="Last Score";
 do rep=1 to 20;
  y=10+rannor(10);
  x=y+rannor(20)*3;
  output;
 end;
run;

ods graphics on / 
      width=7in  
      imagefmt=png
      imagemap=off
      imagename="MyPlot"
      border=off;

ods html file="Body.html" style=journal gpath="."  dpi=100;

proc corr data=one plots=scatter;
 var x; with y;
run;

ods html file="Body.html" style=journal gpath="."  dpi=600;

proc corr data=one plots=scatter;
 var x; with y;
run;




Comments

Popular posts from this blog

DANDA - A macro collection for easier SAS statistical analysis

Objective :  You are running ANOVAs or regressions in SAS, and wish there was a way to avoid writing the dozens of commands needed to conduct the analysis and generate recommended diagnostics and summary of results, not to mention the hundreds of possible options that might be needed to access recommended methods.  A possible solution is to download a copy of danda.sas below, and use this macro collection to run the dozens of commands with one statement.  We will also have future posts covering various uses of danda.sas, giving examples as always. danda.sas is under continued development, check this page for updates. Date                       Version               Link 2021/03/15             2.12.030          danda.sas 2021/03/15             2.12                UserManual.pdf     2012/08/30                 2.11                danda211.sas Example :  You have an RBD split-plot design, so typical SAS code for mixed model ANOVA is proc mixed data=one;   class block treat week;   m

UTF character data, encoding of text

Objective and Background :  You have text data that is UTF encoded and need SAS/R to read and write datasets with that encoding.  If you have ever printed or viewed text information, and seen something like Giuffr?Ÿ’e?ƒe?Ÿƒ?ÿ?›ƒ?ªƒ?›?Ÿ’e›ƒ?ª­?Ÿƒeee, then you are running into this encoding issue.  Computers store text using numbers, with each number assigned to a particular character.  See  https://en.wikipedia.org/wiki/ASCII  to find that the character & is stored as 38 when using the ASCII encoding.  Unicode is popular internationally because it encodes special characters such as accented letters, and UTF-8 is a widely used version ( https://en.wikipedia.org/wiki/UTF-8 ).  In UTF-8 the & character is stored as 26, and you can imagine how the jumbled example above arises from the confusion of what letters are being stored. Solution 1 :  Use options to request that individual datasets be read and written in a particular encoding.  In SAS, specify encoding options on the vario

Factorial ANOVA with control treatment not integrated into the factorial

Factorial treatment designs are popular, due to advantages of research on multiple treatment factors and how they interact.  But if the design includes a control treatment that is not part of the factorial, problems occur in estimation of least squares means.  A typical example is shown here, with 2 fertilizer and 3 irrigation treatments, giving 6 factorial treatment combinations, plus a control that is defined by a 3rd level of fertilizer, and a 4th level of irrigation: Fert1:Irrig2               Fert2:Irrig1             Fert1:Irrig1 Fert2:Irrig3               Fert1:Irrig3             Fert2:Irrig2           Control Other situations might have the control sharing a level of one of the factors, for example the control might be defined as Fert2:Irrig4.  But this still causes problems with estimation of least squares means due to the levels of one factor not occurring with all levels of the other factor. Let's jump into a SAS example, but using random numbers to allow easy creati