SAS TUTORIALS

Best Online SAS Tutorial Tutorials for Beginners

Big Data Analytics

6:51 AM

Graphics in SAS

The two basic graphic procedures in SAS are proc plot and proc gplot. These two procedures are fairly similar; however, proc gplot will usually allow you to produce better looking and more sophisticated graphs than proc plot.

Proc Plot
In proc plot, there are a few nice tricks to know. For example, if you are checking constancy of variance assumption and want to plot the residual variable against more than one independent variable (on separate graphs) you can use:

proc plot data=diag;
plot res*(x1 x2 x3);
run;

(Note that the diag dataset must have been created from a previously run proc reg statement, and thus would contain, in addition to the original dataset the residual values, predicted values, etc.) This way, you don’t have to write more than one plot statement.Another option (using the previous example) to have all three plots on the same graph is to use overlay:

proc plot data=diag;
plot res*(x1 x2 x3) / overlay;
run;

Proc plot contains some options both on the proc statement itself and the plot statement for adjusting theaxes, labeling points, and controlling the size of the plot. These can be found in the help menu.

Proc gplot
Proc gplot has more options and can produce fancier, color graphics. The basics to know about gplot are how to chose symbols and how to draw regression lines. The following example will introduce you to a few of the options in gplot.

symbol value=circle i=r ci=red cv=blue;
proc gplot data=new;
plot y*x1;
run;

The symbol value statement has many other options other than circle (e.g., triangle). The i=r statement draws the linear regression line and gives the linear regression equation (in the log window, not the output window). The ci=red option makes the regression line red and the cv=blue makes the plotted points show
up as blue. The remaining statements are similar to proc plot. Gplot also has the capability to overlay plots and many other options for adjusting axes values, changing colors, changing the legend, etc. which can be found in the help menu.

Exporting graphs
Often, it is helpful to export SAS graphics to a Word and/or a Power Point document. Graphs export best from proc gplot, but it is also possible to export graphs constructed with proc plot, but they may not look as nice in the Word or Power Point documents. There are many different formats in which to save graphs and many options for exporting graphs. The ones presented here are in no way exhaustive of all options. Sometimes, it just takes trial and error to find the best way to export a graph from SAS.

Exporting to Word:
1) From proc gplot, click in the graph you wish to export, pull down the Edit menu, and click on copy. Then, go into Word, pull down the Edit menu, and click on “paste special”. Use the option “Picture” to paste the graph. This is probably the simplest way.
2) Click on the graph you wish to export, pull down the File menu, and go to “Export as Image”. You can choose a variety of different formats in which to save the graph. After you choose your format, go to the Word document. Pull down the Insert menu, click on “object”, click on “from
file”, and put the pathname where your file is located. For both of these ways, using the gplot options first to control the size of the graph may produce better results, although you can size the graph somewhat once it is in Word.

Exporting to Power Point:
1) Save the graph first as a Bitmap file (.bmp) by going to the “Export as Image” as described above. Then, go to your Power Point document and choose the blank slide format. Pull down the “Insert” menu, and go to the “picture” option, and then to the “from file” option. Browse to find your file
and then click “insert”. This will fit the graph nicely to the slide size.
2) The same process can also be achieved by using the “paste special” and “picture” or “bitmap” options as described above for the Word documents.

There was an error in this gadget
Click
For Special
Download