SAS Tutorial — Session 4

Contents
Introduction
Session 1
Session 2
Session 3
Session 4
Session 5
Session 6
Odds -n- Ends
 
 

Objectives

  1. Use the LABEL statement

  2. Use the MEANS procedure

  3. Use the UNIVARIATE

  4. Use the PLOT procedure

LABEL statement

    Use:

    To attach an extended label to a variable

    Syntax:

    LABEL var_name = 'the text of the label';

    Result:

    An expanded label is printed for the labeled variables in the output of many SAS procedures

The LABEL statement attaches an expanded label to the variable names. The general form of the LABEL statement is:

    LABEL var_name = 'label text';

Example:

    LABEL SEX='Gender of subject';

ToC

PROC MEANS statement

    Use:

    To produce univariate descriptive statistics on numeric variables

    Syntax:

    PROC MEANS options;
    VAR var_names;
    CLASS var_names;

    Result:

    Univarate statistics are output for requested variables

Although other procedures produce univariate statistics on numeric variables, PROC MEANS is the easiest to use. PROC MEANS is almost identical to PROC SUMMARY, except that PROC SUMMARY provides no printed output, by default, whereas PROC MEANS does.

Statistics are calculated for each numeric variable listed on the VAR statement. The CLASS statement allows you to have statistics calculated separately for groups of observations, such as males and females.

The output from PROC MEANS is rather detailed, and can include: N, mean, standard deviation, minimum and maximum values, sums, variance, range and many others. Unlike the UNIVARIATE procedure, on the PROC MEANS statement you can select options that specify statistics you wish to have output. The general format for the MEANS procedure is:

    PROC MEANS options;
    Additional procedure statements;

Example:

    PROC MEANS MEAN STD T N RANGE;
    VAR Q1 Q2;

If no options are specified on the PROC MEANS statement, and no additional procedure information statements follow the PROC MEANS statement, such as a VAR statement, all statistics are produced for all variables in the data set.

ToC

PROC UNIVARIATE statement

    Use:

    To produce simple descriptive statistics for numeric variables

    Syntax:

    PROC UNIVARIATE;
    VAR Q1 Q2;

    Result:

    Simple descriptive statistics are output for the requested variables

The output from PROC UNIVARIATE can be even more detailed than that of PROC MEANS, particularly with regard to the distribution of a variable. There are at least 35 statistics that can be requested as well as plots, frequency tables, paired comparison tests, tests of normality, and others. Some of the statistics available are means, standard deviation, mode, kurtosis, range, quartiles, percentiles, Student's T, and many others. The general format of the PROC UNIVARIATE statement is:

    PROC UNIVARIATE options;
    Additional procedure information statements;

Example:

    PROC UNIVARIATE FREQ;
    VAR Q1 Q2;

The above example would produce the standard univariate output. The FREQ option on the PROC UNIVARIATE statement causes the output to also include a list of variable values, frequencies, percentages, and cumulative percentages of variable values.

ToC

PROC PLOT statement

    Use:

    To produce simple X*Y plot of variables

    Syntax:

    PROC PLOT;
    PLOT AGE * Q1;

    Result:

    XY scatterplot of AGE by Q1 is output

PROC PLOT graphs one variable against another producing a scatter plot. The PLOT statement designates the names of the variables to be plotted. The variable to the left of the asterisk (*) is the variable that will appear on the vertical axis. The general format of PROC PLOT is:

    PROC PLOT options;
    PLOT statement;

Example:

    PROC PLOT NOMISS;
    PLOT AGE*Q1;

In the above example, missing values would be excluded from the plot and the variable AGE would appear on the vertical axis.

ToC

Session 4 Exercise

  1. Add a LABEL statement as in the example below.

    Using Pico, edit your SAS program, stored in the file called survey.sas, and add a LABEL statement after the INPUT statement by typing:

      LABEL SEX ='GENDER OF SUBJECT';

    Add PROC MEANS procedure statements as indicated. This will replace the PROC FREQ statement that was used in the previous exercise. Type:

      PROC MEANS;
      VAR AGE Q1 Q2;

  2. Add PROC UNIVARIATE procedure statements at the appropriate place. (See example program below.) This will replace the PROC PRINT statement that was used in the previous exercise.

      PROC UNIVARIATE;
      VAR AGE Q1 Q2;

  3. Add PROC PLOT Procedure statements as shown in the example program. By typing:

      PROC PLOT;
      PLOT AGE*Q2;

  4. Add a PROC FREQ procedure for the variable SEX to see the expanded label by typing:

      PROC FREQ;
      TABLE SEX:

  5. Save the changes you have just made in your program.

    Your SAS program should now look like this:

  6. Now submit your SAS job, at the Linux ($) prompt, type:

      sas survey.sas

    Check your .log and .lst files to look for errors, warnings and notes and to see your procedure output. Then move on to Session 5.

ToC

© University of New Mexico -- last updated -- comments to: docs@unm.edu