Writing a SAS program: the PROC Step

The next step is to create PROC (procedure) steps. SAS procedures read the SAS data and perform various computations and print the results of these computations. The FREQ procedure computes the frequencies on specified variables; the TTEST procedure performs a t-test analysis on the specified variables. In short, the statements that ask SAS to process or analyze a specified data set are known as PROC steps. The DATA steps and PROC steps can be used in any order within a SAS program. As the DATA step starts with a DATA statement the PROC step starts with a PROC statement.

PROC PRINT DATA=dataname;
   VAR var1 var2;

This procedure requests SAS to print data values for variables 1 and 2. If the VAR statement is omitted, data values for each variable in the data set will be printed. DATA=dataname is an optional statement. If this is omitted, SAS selects the most recently created data set within the program. It is a good practice to specify the dataname along with the PROC statement. Replace the dataname with the name of the data created in the DATA step. Printing out a few variables before doing any analysis is a good way to check whether the data are being read by SAS as you want them to be read.

FREQ Statement

PROC FREQ;
   TABLES var1 var2 var1*var2;

This statement produces tables showing distribution of variable values. In the above example SAS will display variable values for var1 and var2, and the combined frequency distributions for var1 and var2. For example, if you wanted to get the gender breakdown for the test scores discussed previously, you would use the following command:

PROC FREQ;
   TABLES sex;

The output generated by this command would look like this:


                                           Cumulative  Cumulative

                SEX   Frequency   Percent   Frequency    Percent

                -------------------------------------------------

                f            5      50.0           5       50.0

                m            5      50.0          10      100.0

MEANS Statement

PROC MEANS;
   VAR var1 var2;

This statement computes descriptive statistics for specified variables. If the VAR statement is omitted, descriptive statistics for each variable in the data set will be calculated.

Again, referring back to the grades data, if you wanted to generate some basic descriptive statistics for the students' test scores, the commands and output would look like this:

PROC MEANS;
   VAR test1 test2 test3;

                The SAS System     10:00 Thursday, November 2, 1995 



       Variable   N          Mean       Std Dev       Minimum       Maximum

       --------------------------------------------------------------------

       TEST1     10    80.1000000    10.4504120    60.0000000    90.0000000

       TEST2     10    82.6000000     8.4616783    72.0000000    96.0000000

       TEST3     10    81.2000000    10.6854002    64.0000000    93.0000000

       --------------------------------------------------------------------

CORR Statement

PROC CORR;
   VAR var1 var2;

A correlation analysis is performed to quantify the strength of association between two numeric variables. For example, if you wanted to see if there were a correlation between student test scores, the commands and output would look like this:

PROC CORR;
   VAR test1 test2 test3;

                     Correlation Analysis



  Pearson Correlation Coefficients / Prob > |R| under Ho: Rho=0  / N = 10



                     TEST1             TEST2             TEST3



   TEST1           1.00000           0.75692           0.91522

                    0.0               0.0113            0.0002



   TEST2           0.75692           1.00000           0.86857

                    0.0113            0.0               0.0011



   TEST3           0.91522           0.86857           1.00000

                    0.0002            0.0011            0.0

ENDSAS statement

By this statement you indicate that there are no more data steps or procedure steps to be read or processed. ENDSAS should be followed by a semicolon (e.g., ENDSAS;). However, an ENDSAS statement during a SAS for Windows session will exit the SAS session and take you to the Microsoft Windows environment.


Next: Writing and Executing a SAS Program
Up: Table of Contents
Prev: Writing a SAS Program: the DATA Step