Friday, May 11, 2007

SAS - 2 : Proc Print n Freq

Objectives

  1. Use PROC PRINT

  2. Use PROC FREQ

Procedure (PROC) statements specify the procedure to be used on the data set you created. The general form of the statements needed to execute a SAS procedure is:

    PROC procedure_name options parameters;
    Additional procedure information statements;

Example:

    PROC PRINT N;
    VAR NAME AGE;

Beginning SAS users should become familiar with these procedures:

    PROC PRINT;
    PROC FREQ;
    PROC UNIVARIATE;
    PROC MEANS;
    PROC PLOT;
    PROC SORT;

In this Session you will learn to use PROC PRINT and PROC FREQ.

PROC PRINT statement

    Use:

    Lists data as a table of observations

    Syntax:

    PROC PRINT;

    Result:

    SAS is asked to print a table of all observations in your data set

PROC PRINT lists data as a table of observations by variables. The general form of the PRINT procedure is:

    PROC PRINT;
    VAR NAME AGE SEX Q1 Q2;

VAR is an additional procedure information statement in the PRINT procedure that allows you to pick out specific variables to be printed in a certain order. Without the VAR statement, all variables in the data set would be output in the print listing.

Sample output from the PRINT procedure

ToC

PROC FREQ statement

    Use:

    To produce a frequency table or 2-way table of your data

    Syntax:

    PROC FREQ;
    TABLES var_name;

PROC FREQ shows the distribution of variable values through a one-way table or through crosstabulation tables. The general form of the PROC FREQ statement is:

    PROC FREQ;
    TABLES list of table requests/options and parameters;

Sample output from the frequency on sex


In order to produce a two-way crosstabulation table the variables to be used in the table should be entered in the TABLES statement as follows:

    PROC FREQ;
    TABLES SEX*Q1;

ToC

Session 3 Exercise

  1. Using Pico, edit your SAS program file called survey.sas.

  2. Add a PROC PRINT statement and a PROC FREQ statement to the end of your program by typing:

      PROC PRINT;
      VAR NAME AGE SEX Ql Q2;
      PROC FREQ;
      TABLES AGE SEX Q1 Q2;

    Your SAS program should now look like this:

  3. Now save your changes and submit your program for processing by SAS, at the $ prompt, type:

      sas survey.sas

    You will know your job is completed when you see the $ prompt again. Now edit the survey.log file and check for errors, warnings, and notes. If your program ran without errors go on to the next session. If your program output shows errors, check the program carefully to make sure it is exactly like the examples given in this tutorial. If you find the errors and correct them, make sure you save your changes and then resubmit your job as above.

No comments: