GLOBAL or Commonly Used Statements

GOPTIONS
SAS/GRAPH automatically uses default colors, type fonts, and fill patterns, allowing you to create graphs with a minimum number of statements. However, you can change many of these defaults with the GOPTIONS statement. Use the GOPTIONS statement to control your output device or control the way your graphics are displayed. A typical statement might look like:

Example:

goptions htext=3 hsize=4 vsize=8 device=tek4105 colors=(red, green, blue);

TITLE, FOOTNOTE LEGEND, AND NOTE statements

These are annotation statements to convey additional information about your graph or to add emphasis. TITLE and FOOTNOTE statements can appear anywhere in your SAS program, and once they are defined, the titles and footnotes remain in effect until they are canceled or the SAS session is ended. NOTE statements are also used by the GSLIDE procedure for defining text in the procedure output area. NOTE statements are local, not global. LEGEND statements are used when you use a plotting technique known as plotting by a third variable..

Example:

title1 color=blue height=1.5 angle=0 rotate=90 ‘text’;

AXIS Statement

You can use the AXIS statement to change the response axis in many different ways in order to enhance your graph’s appearance. The form is AXISn where n is a natural number.

Example:

axis1 label=(‘Total Sales’ justify=right ‘(thousands)’)
offset=(2)
order=(230000 to 320000 by 30000)
value=(t=1 ‘$230’ t=2 ‘$260’ t=3 ‘$290’ t=4 ‘$320’);

SYMBOL and PATTERN Statement

You can use the SYMBOL statement to control the size, shape, and color of the plot symbols.In addition, you can use the interpol option to draw a regression or spline line through your points.

Example:

symbol1 interpol=join color=red value=diamond height=6;
You can use the PATTERN statement to control the patterns for bars, pies, stars, blocks,plots, and maps. Most of these entities are from PROC GCHART, but patterns may be applied to contour levels in PROC GCONTOUR, unit areas and block faces in PROC GMAP, and areas beneath plotted lines in PROC GPLOT.
Example:

pattern1 color=red value=x3;


PROCEDURES

PROC GOPTIONS
This command specifies in the log what SAS/GRAPH options are currently in effect. When you specify your own options in the GOPTIONS statement, those changes will be noted in the output from this procedure.

proc goptions;
run;

PROC GTESTIT
This command is good for checking whether or not you’ve specified the correct device driver. It produces a standard test pattern, and indicates in the log what colors are valid for that device.

proc gtestit;
run;

PROC GSLIDE
A procedure for creating text slides. The minimum code to produce a slide creates an empty square:

proc gslide border;
run;
A typical example incorporates titles, notes, and footnotes:

filename metafile ‘chartype meta g’;
goptions device=macfs;
proc gslide border;
title1 h=1 font=hwmgd001 ‘Demonstration of PROC GSLIDE and’;
title2 h=1 f=hwmgd001 ‘utilizing the hardware fonts’;
title3 h=.5;
note font=hwmgd001 ‘Chicago-12 chartype=1’;
note f=hwmgd002 ‘Geneva-9 chartype=2’;
note f=hwmgd003 ‘Monaco-9 chartype=3’;
note f=hwmgd004 ‘Times-12 chartype=4’;
note f=hwmgd005 ‘Times-12-Bold chartype=5’;
note f=hwmgd006 ‘Times-12-Italic chartype=6’;
note f=hwmgd007 ‘Times-12-Bold-Italic chartype=7’;
note f=hwmgd008 ‘Helvetica-12 chartype=8’;
note f=hwmgd009 ‘Helvetica-12-Bold chartype=9’;
note f=hwmgd010 ‘Helvetica-12-Italic chartype=10’;
note f=hwmgd011 ‘Helvetica-12-Bold-Italic chartype=11’;
note f=hwmgd012 ‘Courier-12 chartype=12’;
note f=hwmgd013 ‘Courier-12-Bold chartype=13’;
note f=hwmgd014 ‘Courier-12-Italic chartype=14’;
footnote1 f=hwmgd015 angle=45 ‘Courier-12-Bold-Italic chartype=15’;
run;
quit;

PROC GCHART
The GCHART procedure produces vertical and horizontal bar charts, block charts, pie charts, and star charts. These charts graphically represent the value of a statistic calculated for one or more variables in an input SAS data set.

Example of Bar Charts:

title1 ‘Ages of Men and Women in Wellness Program’;
pattern1 value=empty;
proc gchart data=sampsio.fitness;
hbar age / type=mean sumvar=heart clm=75 errorbar=both;
hbar age / type=mean sumvar=heart errorbar=bars;
hbar age / type=mean sumvar=heart errorbar=top;
run;
quit;
Data for this example are in the following form:

OBS TEACHER AGE SEX HEART EXER
1 Yang 28 M 86 2
2 Yang 41 M 76 3
3 Yang 30 M 78 2
4 Yang 39 F 90 1
10 Reed 28 F 84 2
11 Reed 33 F 56 4

PROC GPLOT
The GPlot procedure creates xyz-line charts.

Example of Plotting 2 linearly-related variables

title1 h=2 ‘Linear Regression’;
proc reg data=class;
model weight = height;
plot weight*height;
run;
goptions ftext=triplex;
symbol1 v=star I=RL;
proc gplot data=class;
plot weight*height;
run;
quit;
Data for this example are in the following form:

name height weight age
Alfred 69.0 112.5 14
Alice 56.5 84.0 13
Barbara 65.3 98.0 13
Carol 62.8 102.5 14
Henry 63.5 102.5 14
James 57.3 83.0 12
Jane 59.8 84.5 12
Janet 62.5 112.5 15
Jeffrey 62.5 84.0 13

Example of Plotting By a Third Variable:

title;
title2 font=triplex height=1.5 ‘This is a title.’;
symbol1 width=1 color=blue value=star interpol=join;
symbol2 w=1 c=yellow v=diamond i=join;
symbol3 w=1 c=red v=circle i=join;
symbol4 w=1 c=green v=triangle i=join;
symbol5 w=1 c=cyan v=square i=join;
axis1 label=(f=triplex h=1.5 a=90 ‘Y-Values’) order=(40 to 60 by 5)
value=(f=triplex h=.8);
axis2 label=(f=triplex h=1.5 ‘Group’) offset=(5 pct) minor=none

value=(f=triplex h=1 ‘PC’ ‘C’ ‘A’ ‘M’);
legend1 label=(f=triplex h=1.5 ‘This is a Legend’)

value=(f=triplex h=1);
proc gplot data=scores;
plot y*group=category / vaxis=axis1 haxis=axis2 legend=legend1;
run;
quit;

Data for this example are in the following form:

OBS GROUP CATEGORY Y
1 1 thr 46.309
2 1 tis 44.074
3 1 tdr 45.559
4 1 ter 44.440
5 1 tsr 45.594
6 2 thr 50.461
7 2 tis 52.006

GRAPHIC OUTPUT

TERMINALS
The only visual option available is to use the following driver on a Macintosh connected via Telnet.
DEVICE=IBM3179

PRINTERS
Laser Output is available via several DEVICE= options. These are listed below:

DEVICE=Q2200PS

When using the Q2200PS driver, specify to SAS that you are using it when you go into SAS, i.e.:

SAS filename (DEVICE=Q2200PS
DEVICE=LASER

The LASER driver can be used from within a SAS session, such as during a SAS/ASSIST session, or in Display Manager. After seeing your output on the terminal, you can run a subsequent job with LASER specified as the device, and the graphics will go to the laser printer.

PLOTTERS
DEVICE=PLOTTER

When using the PLOTTER driver, specify to SAS that you are using it when you go into SAS, i.e.:

SAS filename (DEVICE=PLOTTER
DEVICE=COLOR

The COLOR driver can be used from within a SAS session, such as during a SAS/ASSIST session, or in Display Manager. After seeing your output on the terminal, you can run a subsequent job with COLOR specified as the device, and the graphics will go to the electrostatic plotter. The COLOR driver is derived from the PLOTTER driver, but it is limited to only 13 colors. To get a list of the available colors sent to the SASLOG, type:

goptions nodisplay device=color;
proc gtestit; run;

FILES
Often you will want to save your graphics to a file. SAS often uses the option GACCESS to link the grpahics to a graphics stream file. A filename statement before the run points to the CMS file or destination for the graphics stream file.

Downloading Graphics to an IBM Compatible PC

CGM files

Microsoft Word For Windows

To send your graphics to Microsoft’s Word For Windows, you’ll need to include the following lines in your SAS/GRAPH program:

filename gsasfile ‘filename cgm filemode’;
goptions device=cgmmwwc;
SAS/GRAPH code…
Next, you’ll need to download the file you create. Be sure to download in BINARY format. Once the file is on your PC, make sure you have the CGM filter CGMIMP.FLT installed in the MSAPPSGRPHFLT directory. From Word For Windows, select INSERT, select PICTURE, select your file, and size the graph appropriately.

WordPerfect 5.1

To send your graphics to WordPerfect, you’ll need to include the following lines in your SAS/GRAPH program:

filename gsasfile ‘filename cgm filemode’;
goptions device=cgmwp;
SAS/GRAPH code…
Next, you’ll need to download the file you create. Be sure to download in BINARY format. Once the file is on your PC get into WordPerfect 5.1. Move the cursor to a position where you want the graphic to be. Activate the graphics function ; <1> for Figure; <1> for Create; <1> for File; Enter the graphics file to be read; and finally, choose the placement of the graphic in your document.

Downloading Graphics to a Macintosh

PICT files

The META application gives SAS/GRAPH users the capability of transferring graphics output from the SAS System to their Macintosh computer. Once the graphics output is transferred to the Macintosh, META allows users to store the graph in PICT format for import into other Macintosh software product.s All graphics examples in this document were PICT files imported into MS Word on the Mac. All were originally created on the mainframe using SAS 6.07.

To send your graphics to a Mac, you’ll need to include the following lines in your SAS/GRAPH program:
filename metafile ‘filename filetype filemode’;
goptions device=macfs;
SAS/GRAPH code…
Next, you’ll need to download the file you create. Be sure to download it as TEXT, as opposed to BINARY. Once the file is on your Mac, make sure you have the META application (which can be obtained by bringing a Mac diskette to my office). Launch the META application and open your new graphics metafile. After a conversion process, the META application will show you your graph in a window. You then SAVE AS in PICT format.