Note on How to Save Graphs from SAS/Graph and SAS/INSIGHT



How to Export Graphs from SAS

Introduction:

This handout describes exporting graphs that were created using procedures available in SAS 9.1 or SAS 9.2 (Proc Univariate and Proc Gplot), and exporting graphs created using Statistical Graphics procedures available starting with SAS 9.2.

Graphs generated using Proc Gplot or Proc Univariate will appear in the SAS/Graph window. You can Export these graphs to a file and then open them in Microsoft Word, PowerPoint, or other application. If you save a graphics file using a .png (portable network graphics) format, it produces a very small file. You can also use any of the other commonly used formats for graphs supported by SAS (.bmp, .gif, .tif).

Graphs generated using Statistical Graphics procedures (Proc Sgplot, Proc Sgscatter, Proc Sgpanel) will show up in your SAS Current Folder in Windows, and will automatically be .png files. These graphics files can also be easily imported into many different applications.

Create Graphs using Proc Univariate and Proc Gplot in SAS 9.1 or 9.2:

The following instructions show how to create a graphics in the SAS/Graph window using either Proc Univariate or Proc Gplot. These graphs can be produced using either SAS 9.1 or 9.2.

To make these examples work you must first get the baseball.sas7bdat dataset by downloading it from my web page at:



Click once on the file: baseball.sas7bdat and save it to a folder on your desktop or in another location. (Do not double-click on this dataset, or it will open in your browser, and will be unusable from there). Submit the following SAS commands to create the graph. Note that the libname statement points to the folder where you saved the dataset. In the example below, the file was saved into a folder called MYLIB on my desktop.

libname mylib "c:\documents and settings\kwelch\desktop\mylib";

title "Distribution of Salary";

proc univariate data=mylib.baseball noprint;

var salary;

histogram;

run;

[pic]

data baseball2;

set mylib.baseball;

log_salary = log(salary);

run;

symbol1 value=dot height=.5 interpol=rlcli95 ;

title "Regression Plot with Log Salary";

proc gplot data=baseball2;

plot log_salary * no_hits ;

run; quit;

[pic]

To Export graphs from the Graph Window:

Go to the SAS/Graph window. With the appropriate graph open in the Graph Window, Go to File...Export as Image....Select the File type you want (e.g. .png), Browse to the location where you wish to save the graphics file, and type the file name, e.g.

histogram_salary.png

Using Statistical Graphics Procedures to Create Graphs in SAS 9.2:

The following commands show how to create similar graphs using Proc Sgplot in SAS 9.2. Proc Sgplot is one of the Statistical Graphics procedures, which also include Proc Sgscatter and Proc Sgpanel. These procedures are available in SAS 9.2, and not in earlier releases.

To make the examples in this handout work, you must first get the baseball.sas7bdat data set by downloading it from my web page at:



Click once on the file: baseball.sas7bdat and save it to a folder on your desktop or in another location. (Do not double-click on this dataset, or it will open in your browser, and will be unusable from there). Submit the following SAS commands to create the graph. Note that the libname statement points to the folder where you saved the dataset. In the example below, the file was saved into a folder called MYLIB on my desktop.

libname mylib "c:\documents and settings\kwelch\desktop\mylib";

title "Distribution of Salary";

proc sgplot data=mylib.baseball noprint;

histogram salary;

run;

[pic]

data baseball2;

set mylib.baseball;

log_salary = log(salary);

run;

title "Regression Plot with Log Salary";

proc sgplot data=baseball2;

reg x=no_hits y=log_salary / cli clm;

run;

[pic]

You can get a handout with more information illustrating how to create graphs using Statistical Graphics procedures in SAS 9.2 at:



To Export graphs created using Statistical Graphics procedures:

You do not need to export graphs created using Statistical Graphics procedures. They will automatically be saved to your Current Folder in Windows as .png files. You can double-click on the .png files to view them, or view them as thumbnails. They will be given names such as SGPlot.png, or SGPlot1.png, etc.

To set the Current Folder, double-click on the location listed at the bottom of your SAS desktop and browse to the folder you wish to use. Make sure you have double-clicked on the name of the folder. Do this before you submit the SAS commands to create the Statistical Graphs.

Within SAS, graphs created using Statistical Graphics procedures will not go to your SAS/Graph window, but instead will be in the Results window. Double-click on the procedure name and then double-click on the individual graphs. You can browse forward and backward through the graphs once you have created them.

[pic][pic]

[pic]

To bring graphics files into a Word document:

You can simply drag and drop a graphics file into word, or you can import it using the steps shown below:

Make sure you are not at the beginning or end of a document, or it will be difficult to work with the graph. Place your mouse somewhere in the middle of several blank lines in the document. Go to Insert…Picture from file… Browse until you get to your graph (e.g., histogram_salary.png).

You can resize the graph by clicking your mouse anywhere in the graph to get the outline. Then grab the lower right corner with your mouse (you should see an arrow going northwest to southeast) and move it up and to the left to make it smaller, or down and to the right to make it larger. You can't easily edit the graph in Word. If you're using a .png file, you can simply drag and drop it into Word.

To bring graphics files into PowerPoint:

You can drag and drop a graphics file into PowerPoint, or you can import it using the steps shown below:

Insert a new slide. Go to File...Insert...Picture. Browse until you get to your graph,

histogram_salary.png

Click on Insert.

Note: any titles you used in SAS will appear on your graph.

You can resize the graph by clicking your mouse anywhere in the graph to get the outline. Then grab the lower right corner with your mouse (you should see an arrow going northwest to southeast) and move it up and to the left to make it smaller, or down and to the right to make it larger. You can't easily edit the graph in Power Point.

Have fun!!

-----------------------

Set the current folder by double-clicking here. Graphs created by Statistical Graphics procedures will automatically be saved here.

Double-click here in the Results window to view the graph.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download