Base SAS 9.1 Procedures Guide, Volumes 1, 2, 3 and 4
Example 1: Plotting a Single Variable
Procedure features:
ID statement
PLOT statement arguments:
-
simple plot request
-
POS=
This example
-
uses a single PLOT statement to plot sales of refrigerators
-
specifies the number of print positions to use for the horizontal axis of the plot
-
provides context for the points in the plot by printing in the listing the values of two variables that are not in the plot.
Program
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=60;
Create the SALES data set. SALES contains weekly information on the sales of refrigerators and stoves by two sales representatives.
data sales; input Month Week Seller $ Icebox Stove; datalines; 1 1 Kreitz 3450.94 1312.61 1 1 LeGrange 2520.04 728.13 1 2 Kreitz 3240.67 222.35 1 2 LeGrange 2675.42 184.24 1 3 Kreitz 3160.45 2263.33 1 3 LeGrange 2805.35 267.35 1 4 Kreitz 3400.24 1787.45 1 4 LeGrange 2870.61 274.51 2 1 Kreitz 3550.43 2910.37 2 1 LeGrange 2730.09 397.98 2 2 Kreitz 3385.74 819.69 2 2 LeGrange 2670.93 2242.24 ;
Plot sales of refrigerators. The plot variable, Icebox, appears in both the listing and the output. POS= provides 50 print positions for the horizontal axis.
proc timeplot data=sales; plot icebox / pos=50;
Label the rows in the listing. The values of the ID variables, Month and Week, are used to uniquely identify each row of the listing.
id month week;
Specify the titles.
title 'Weekly Sales of Iceboxes'; title2 'for the'; title3 'First Six Weeks of the Year'; run;
Output
The column headers in the listing are the variables names . The plot uses the default plotting symbol, which is the first character of the plot variable s name .
Weekly Sales of Iceboxes 1 for the First Six Weeks of the Year Month Week Icebox min max 2520.04 3550.43 *--------------------------------------------------* 1 1 3450.94 I 1 1 2520.04 I 1 2 3240.67 I 1 2 2675.42 I 1 3 3160.45 I 1 3 2805.35 I 1 4 3400.24 I 1 4 2870.61 I 2 1 3550.43 I 2 1 2730.09 I 2 2 3385.74 I 2 2 2670.93 I *--------------------------------------------------*
Example 2: Customizing an Axis and a Plotting Symbol
Procedure features:
ID statement
PLOT statement arguments:
-
using a plotting symbol
-
AXIS=
Other features:
LABEL statement
PROC FORMAT
SAS system options:
-
FMTSEARCH=
Data set: SALES on page 1313
This example
-
specifies the character to use as the plotting symbol
-
specifies the minimum and maximum values for the horizontal axis as well as the interval represented by each print position
-
provides context for the points in the plot by printing in the listing the values of two variables that are not in the plot
-
uses a variable s label as a column header in the listing
-
creates and uses a permanent format.
Program
Declare the PROCLIB SAS data library.
libname proclib ' SAS-data-library ';
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page. FMTSEARCH= adds the SAS data library PROCLIB to the search path that is used to locate formats.
options nodate pageno=1 linesize=80 pagesize=60 fmtsearch=(proclib);
Create a format for the Month variable. PROC FORMAT creates a permanent format for Month. The LIBRARY= option specifies a permanent storage location so that the formats are available in subsequent SAS sessions. This format is used for examples throughout this chapter.
proc format library=proclib; value monthfmt 1='January' 2='February'; run;
Plot sales of refrigerators. The plot variable, Icebox, appears in both the listing and the output. The plotting symbol is R . AXIS= sets the minimum value of the axis to 2500 and the maximum value to 3600. BY 25 specifies that each print position on the axis represents 25 units (in this case, dollars).
proc timeplot data=sales; plot icebox='R' / axis=2500 to 3600 by 25;
Label the rows in the listing. The values of the ID variables, Month and Week, are used to uniquely identify each row of the listing.
id month week;
Apply a label to the sales column in the listing. The LABEL statement associates a label with the variable Icebox for the duration of the PROC TIMEPLOT step. PROC TIMEPLOT uses the label as the column header in the listing.
label icebox='Refrigerator';
Apply the MONTHFMT. format to the Month variable. The FORMAT statement assigns a format to use for Month in the report.
format month monthfmt.;
Specify the titles.
title 'Weekly Sales of Refrigerators'; title2 'for the'; title3 'First Six Weeks of the Year'; run;
Output
The column headers in the listing are the variables' names (for Month and Week, which have no labels) and the variable's label (for Icebox, which has a label). The plotting symbol is R (for Refrigerator).
Weekly Sales of Refrigerators 1 for the First Six Weeks of the Year Month Week Refrigerator min max 2500 3600 *---------------------------------------------* January 1 3450.94 R January 1 2520.04 R January 2 3240.67 R January 2 2675.42 R January 3 3160.45 R January 3 2805.35 R January 4 3400.24 R January 4 2870.61 R February 1 3550.43 R February 1 2730.09 R February 2 3385.74 R February 2 2670.93 R *---------------------------------------------*
Example 3: Using a Variable for a Plotting Symbol
Procedure features:
ID statement
PLOT statement arguments:
-
using a variable as the plotting symbol
-
JOINREF
-
NPP
-
REF=
-
REFCHAR=
Data set: SALES on page 1313
Formats: MONTHFMT. on page 1316
This example
-
specifies a variable to use as the plotting symbol to distinguish between points for each of two sales representatives
-
suppresses the printing of the values of the plot variable in the listing
-
draws a reference line to a specified value on the axis and specifies the character to use to draw the line
-
connects the leftmost and rightmost symbols on each line of the plot. Program
Declare the PROCLIB SAS data library.
libname proclib ' SAS-data-library ';
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page. FMTSEARCH= adds the SAS data library PROCLIB to the search path that is used to locate formats.
options nodate pageno=1 linesize=80 pagesize=60 fmtsearch=(proclib);
Plot sales of stoves. The PLOT statement specifies both the plotting variable, Stove, and a symbol variable, Seller. The plotting symbol is the first letter of the formatted value of the Seller (in this case, L or K ).
proc timeplot data=sales; plot stove=seller /
Suppress the appearance of the plotting variable in the listing. The values of the Stove variable will not appear in the listing.
npp
Create a reference line on the plot. REF= and REFCHAR= draw a line of colons at the sales target of $1500.
ref=1500 refchar=':'
Draw a line between the symbols on each line of the plot. In this plot, JOINREF connects each plotting symbol to the reference line.
joinref
Customize the horizontal axis. AXIS= sets the minimum value of the horizontal axis to 100 and the maximum value to 3000. BY 50 specifies that each print position on the axis represents 50 units (in this case, dollars).
axis=100 to 3000 by 50;
Label the rows in the listing. The values of the ID variables, Month and Week, are used to identify each row of the listing.
id month week;
Apply the MONTHFMT. format to the Month variable. The FORMAT statement assigns a format to use for Month in the report.
format month monthfmt.;
Specify the titles.
title 'Weekly Sales of Stoves'; title2 'Compared to Target Sales of 00'; title3 'K for Kreitz; L for LeGrange'; run;
Output
The plot uses the first letter of the value of Seller as the plotting symbol.
Weekly Sales of Stoves 1 Compared to Target Sales of 00 K for Kreitz; L for LeGrange Month Week min max 100 3000 *-----------------------------------------------------------* January 1 K---: January 1 L--------------: January 2 K-------------------------: January 2 L-------------------------: January 3 :--------------K January 3 L------------------------: January 4 :-----K January 4 L------------------------: February 1 :---------------------------K February 1 L---------------------: February 2 K-------------: February 2 :--------------L *-----------------------------------------------------------*
Example 4: Superimposing Two Plots
Procedure features:
PROC TIMEPLOT statement options:
-
MAXDEC=
PLOT statement arguments:
-
using two types of plot requests
-
OVERLAY
-
REF=MEAN( variable(s) )
-
REVERSE
Data set: SALES on page 1313
This example
-
superimposes two plots on one set of axes
-
specifies a variable to use as the plotting symbol for one plot and a character to use as the plotting symbol for the other plot
-
draws a reference line to the mean value of each of the two variables plotted
-
reverses the labeling of the axis so that the largest value is at the far left of the plot.
Program
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=60;
Specify the number of decimal places to display. MAXDEC= specifies the number of decimal places to display in the listing.
proc timeplot data=sales maxdec=0;
Plot sales of both stoves and refrigerators. The PLOT statement requests two plots. One plot uses the first letter of the formatted value of Seller to plot the values of Stove. The other uses the letter R (to match the label Refrigerators) to plot the value of Icebox.
plot stove=seller icebox='R' /
Print both plots on the same set of axes.
overlay
Create two reference lines on the plot. REF= draws two reference lines: one perpendicular to the mean of Stove, the other perpendicular to the mean of Icebox.
ref=mean(stove icebox)
Order the values on the horizontal axis from largest to smallest.
reverse;
Apply a label to the sales column in the listing. The LABEL statement associates a label with the variable Icebox for the duration of the PROC TIMEPLOT step. PROC TIMEPLOT uses the label as the column header in the listing.
label icebox='Refrigerators';
Specify the titles.
title 'Weekly Sales of Stoves and Refrigerators'; title2 'for the'; title3 'First Six Weeks of the Year'; run;
Output
The column header for the variable Icebox in the listing is the variable's label (Refrigerators). One plot uses the first letter of the value of Seller as the plotting symbol. The other plot uses the letter R .
Weekly Sales of Stoves and Refrigerators 1 for the First Six Weeks of the Year Stove Refrigerators max min 3550.43 184.24 *----------------------------------------------------------* 1313 3451 R K 728 2520 R L 222 3241 R K 184 2675 R L 2263 3160 R K 267 2805 R L 1787 3400 R K 275 2871 R L 2910 3550 R K 398 2730 R L 820 3386 R K 2242 2671 R L *----------------------------------------------------------*
Example 5: Showing Multiple Observations on One Line of a Plot
Procedure features:
-
CLASS statement
-
PLOT statement arguments:
-
creating multiple plots
-
NOSYMNAME
-
OVPCHAR=
-
Data set: SALES on page 1313
Formats: MONTHFMT. on page 1316
This example
-
groups observations for the same month and week so that sales for the two sales representatives for the same week appear on the same line of the plot
-
specifies a variable to use as the plotting symbol
-
suppresses the name of the plotting variable from one plot
-
specifies a size for the plots so that they both occupy the same amount of space.
Program
Declare the PROCLIB SAS data library.
libname proclib ' SAS-data-library ';
Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGENO= specifies the starting page number. LINESIZE= specifies the output line length, and PAGESIZE= specifies the number of lines on an output page. FMTSEARCH= adds the SAS data library PROCLIB to the search path that is used to locate formats.
options nodate pageno=1 linesize=80 pagesize=60 fmtsearch=(proclib);
Specify subgroups for the analysis. The CLASS statement groups all observations with the same values of Month and Week into one line in the output. Using the CLASS statement with a symbol variable produces in the listing one column of the plot variable for each value of the symbol variable.
proc timeplot data=sales; class month week;
Plot sales of stoves and refrigerators. Each PLOT statement produces a separate plot. The plotting symbol is the first character of the formatted value of the symbol variable: K for Kreitz; L for LeGrange. POS= specifies that each plot uses 25 print positions for the horizontal axis. OVPCHAR= designates the exclamation point as the plotting symbol when the plotting symbols coincide. NOSYMNAME suppresses the name of the symbol variable Seller from the second listing.
plot stove=seller / pos=25 ovpchar='!'; plot icebox=seller / pos=25 ovpchar='!' nosymname;
Apply formats to values in the listing. The FORMAT statement assigns formats to use for Stove, Icebox, and Month in the report. The TITLE statement specifies a title.
format stove icebox dollar10.2 month monthfmt.;
Specify the title.
title 'Weekly Appliance Sales for the First Quarter'; run;
Output
Weekly Appliance Sales for the First Quarter 1 Seller :Kreitz Seller :LeGrange Month Week Stove Stove min max 4.24 ,910.37 *----------------------------* January 1 ,312.61 8.13 L K January 2 2.35 4.24 ! January 3 ,263.33 7.35 L K January 4 ,787.45 4.51 L K February 1 ,910.37 7.98 L K February 2 9.69 ,242.24 K L *----------------------------*
Weekly Appliance Sales for the First Quarter 2 Kreitz LeGrange Month Week Icebox Icebox min max ,520.04 ,550.43 *--------------------------* January 1 ,450.94 ,520.04 L K January 2 ,240.67 ,675.42 L K January 3 ,160.45 ,805.35 L K January 4 ,400.24 ,870.61 L K February 1 ,550.43 ,730.09 L K February 2 ,385.74 ,670.93 L K *--------------------------*