How to access SAS sample programs

10

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 macro to find it:

   %put %sysget(sasroot);
     C:\Program Files\SASHome\SASFoundation\9.3

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

     C:\Program Files\SASHome\SASFoundation\9.3\stat\sample\qregex4.sas

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.

Share

About Author

Rick Wicklin

Distinguished Researcher in Computational Statistics

Rick Wicklin, PhD, is a distinguished researcher in computational statistics at SAS and is a principal developer of SAS/IML software. His areas of expertise include computational statistics, simulation, statistical graphics, and modern methods in statistical data analysis. Rick is author of the books Statistical Programming with SAS/IML Software and Simulating Data with SAS.

10 Comments

  1. Hi

    You do not need a data step to run the macro statement:
    %put %sysget(sasroot);

    If you want to do the same thing using data step code, it makes more sence to do it like this:
    data _null_;
    sasroot = sysget('sasroot');
    put sasroot;
    run;

    Regards

  2. Hello Rick,

    I am fairly new to SAS programming (I have passed the Base SAS Certification Exam) but am truly limited to Data step type manipulations at this point. I am having a difficult time finding references online to assist (in a very methodical way) me in programmatically creating transition matrices (for example in a Credit Risk Cohort approach framework.) Charlie Huang (http://www.sasanalysis.com/2010/12/scorecard-to-create-transition-matrices.html) has provided a wonderful example of code for the actual transition matrix generation, but I am having trouble preparing the data to be used in his code. Any chance you could blog a bit about this exercise? Thanks a million!

  3. Pingback: How to access any program or data set that appears in the SAS/STAT documentation - The DO Loop

  4. built into most environments where SAS is launched are the product specific sample programs and data. They are hiding below the surface, just waiting for the adventurer (including you)!
    Just try running the code:

    proc contents data= sampsio._all_ nods details; run ;

    Although the library SAMPSIO does not reveal itself before you use it, it is probably sitting there quietly waiting to be investigated.

    This will save you any fuss with SASROOT
    (until you really need it)

    ;-)

  5. Pingback: Top 3 stocking stuffers for coders | SAS Learning Post

  6. Pingback: Five reasons to check out the new SAS analytical documentation - The DO Loop

Leave A Reply

Back to Top