Have you ever wanted to run a sample program from the SAS documentation or wanted to use a data set that appears in the SAS documentation? You can: all programs and data sets in the documentation are distributed with SAS, you just have to know where to look!
Sample data in the SASHELP library
The data that are used in the SAS documentation are obtained in one of two ways: from a data set in the SASHELP library, or from a DATA step.
Many documentation examples use data in the SASHELP library, such as the Class, Iris, and Cars data sets. To use these data sets, specify the two-level name (libref.DataSetName) on the DATA= option of a procedure. For example, to display descriptive statistics about numerical variables in the Iris data, use the following call to the MEANS procedure:
title "Descriptive statistics for SASHELP.Iris"; proc means data=sashelp.iris; run;
In other examples, the data is presented as a DATA step. However, sometimes the DATA step is so long that all of the data do not appear in the documentation. For example, the documentation of the QUANTREG procedure contains the following truncated DATA step:
data ozone; days = _n_; input ozone @@; datalines; 0.0060 0.0060 0.0320 0.0320 0.0320 0.0150 0.0150 0.0150 0.0200 0.0200 0.0160 0.0070 0.0270 0.0160 0.0150 0.0240 0.0220 0.0220 0.0220 0.0185 0.0150 0.0150 0.0110 0.0070 0.0070 0.0240 0.0380 0.0240 0.0265 0.0290 ... more lines ... 0.0220 0.0210 0.0210 0.0130 0.0130 0.0130 0.0330 0.0330 0.0330 0.0325 0.0320 0.0320 0.0320 0.0120 0.0200 0.0200 0.0200 0.0320 0.0320 0.0250 0.0180 0.0180 0.0270 0.0270 0.0290 ;
The complete data is contained in the sample program for this example. The next sections show how to access sample programs.
Access sample programs from the Help menu
You can access SAS sample programs by using the Help menu inside the SAS Windowing Environment, which is the default GUI environment. The following image shows a way to access the SAS/STAT sample programs by using the SAS GUI:
Access sample programs from the installation directory
Michael A. Raithel, in a SAS Tip on sasCommunity.org, points out that sample programs exist for all products, and gives examples of directories in which you can find them. For example, on my desktop PC, which is running SAS 9.3, I can browse to
C:\Program Files\SASHome\SASFoundation\9.3\ProductName\sample\in order to see the sample programs.
You need to replace ProductName with the name of a SAS product, such as stat or ets. But how can you find the path of the "root directory" for your SAS installation? You can run the following DATA step in order to find it:
data _NULL_; %put %sysget(sasroot); run;
This is the value of sasroot that Michael refers to in his article. As Michael points out, it can be useful to browse programs in the sample directory, especially for products that you are trying to learn. The names of the files can be somewhat cryptic, so you should to use a search tool to find the correct file. For example, if you search the SAS/STAT sample directory for the term "data ozone," you will discover that the DATA step for the PROC QUANTREG example is in the file qregex4.sas. Therefore, the complete path for the PROC QUANTREG example on my PC is
I'd like to be able to end this post by saying "the examples for PROC IML are great and help you learn how to program in the SAS/IML language." Unfortunately, many of the SAS/IML examples (which are based on the documentation) are old and do not contain many comments or explanatory text. But don't dispair. For Getting Started examples, read The DO Loop every Monday.