clocktower
Index A-Z
From the Chancellor
Visitors
Alumni
People Finder
For the Media
For Parents
Jobs
SalukiNet
SIUC Intranet
Athletics
Events Calendar
Weather
IT Home
Get Help
How Do I
FAQ
Get Network ID
Get UNIX ID
Get Mypage ID
Change Password
Services Index
Doc Index
line

SAS on the Mainframe

Print friendly page

SAS (Statistical Analysis System) is a computer software package for the processing, storage, and retrieval of data. Some important features of SAS are its ability to plot and graph data, compute descriptive and multivariate statistics, produce tables and summarized results for reports, and create and manipulate SAS data files.

Programming With SAS

The first step in using any statistical package is to acquire a CMS ID number. Each user will receive a logon ID and a password. With access to the computer, the user is ready to write and successfully run a SAS program. SAS programming requires knowledge of three areas: (1) JCL to run the program; (2) the DATA step to input and modify variables; and (3) the PROC step to process data and output the results. The following text discusses these three areas.

- JCL -

The Job Control Language (JCL) conveys information to the computer about the user and the task to be performed. In the example below, the MVS Operating System JCL statements begin in column one with a slash (/).

  //GR1234  JOB  (1,1234),SMITH,TIME=1,REGION=4096K,CLASS=A
  //*LOGONID logonid
  //*PASSWORD password
  /*ROUTE  PRINT  SIUCMVSA
  //STEP1  EXEC SAS
  //SYSIN  DD  *

The first JCL command line gives general program information. The program output is printed and placed by the operators in output bin 34. The output bin is identified by the last two digits in the distribution field (1234). The user is identified by a name or nickname that is placed on the first JCL card (SMITH). If a name contains blanks or symbols other than periods, it must be enclosed in single quotes (e.g., 'JANE SMITH'). A time limit for the computer run is given by the user. In this example, one minute is allotted for the job. It is possible to increase the time limit, but this will result in a lower priority for job processing. If more memory than the default value of 1024K is needed, it must be specified in the REGION parameter of the JOB card (REGION=4096K). Also, the priority (CLASS) of the job must be specified. A job that is allocated one minute is a class A job (i.e., the highest priority). (For information on job classes, refer to the document entitled MVS Operating System.)

The second and third JCL statements provide your MVS logon ID and password, which are needed to identify you to the mainframe security system.

The fourth JCL statement identifies the output destination of the job. In the example, printed output is routed to the Wham Computing Facility. The fifth and sixth JCL lines identify that the software package SAS is to be used to run the program, and that the program immediately follows the JCL statements.

In the following example, two command lines that have a slash (/) in column one are placed at the end of the program. These inform the computer that the program input is finished and processing ends.

  /*
  //
  

- DATA Step -

An SAS data set is created in the DATA step of a program. Here the data set is given a name, the variables and their formats are identified and modified, and new variables are created.

DATA EXAMS;  
  INPUT @1 NAME $15. @17 SEX $1. @20 AGE 2. @24 DEPT 2.     
  	@28 GPA 4. @34 SCORE1 3. @39 SCORE2 3. @44 SCORE3 3.;
	

The name of a data set is given by the DATA statement. In the example above, the data set is named EXAMS. The INPUT statement identifies each variable and the format of its values. The first variable is NAME. The values of this character variable begin in column one (@1) and continue for 15 spaces ($15.). Another variable in the data set is AGE. The values of this numeric variable start in column 20 (@20) and continue for two spaces (2.).

AVESCORE = MEAN (OF SCORE1-SCORE3);
IF AVESCORE >= 90 THEN GRADE = 'A';
   ELSE IF AVESCORE >= 80 THEN GRADE = 'B';
   ELSE IF AVESCORE >= 70 THEN GRADE = 'C';
   ELSE IF AVESCORE >= 60 THEN GRADE = 'D';
   ELSE GRADE = 'F';

In this example, the new variable AVESCORE (i.e., average score) is computed as the mean of three test scores. Another new variable GRADE is then assigned values based upon this average test score.

     CARDS;
     ELIZABETH   F 202 3.2582  93 89
     ALAN        M 215 3.7100  89 96
     LISA        F 234 3.8492 100 96
     MICHAEL     M 223 3.4685  89 91
     DAVID       M 191 2.7669  77 85
    

The last statement to appear in the DATA step is the CARDS statement. It indicates that the data lines to be processed are located immediately after this programming statement.

 

- PROC Step -

SAS procedures are previously written programs which are invoked simply by calling the procedure by name. The SAS keyword PROC tells the computer that a procedure is being called. The procedure name appears immediately following this keyword, and identifies the particular set of programs to be used. In the sample program, three procedures are invoked.

  PROC SORT;
   BY SEX NAME;
   

The statement PROC SORT activates a procedure which sorts the observations by the variables listed in the BY statement. In this instance, all observations are sorted by sex and, within sex, by name.

  PROC PRINT;
   VAR NAME AGE DEPT GRADE;
   BY SEX;
   

A second procedure is invoked by the statement PROC PRINT. This procedure prints the variables and their values according to any specifications which are given. Four variables are specified by the VAR statement to be printed (NAME, AGE, DEPT, and GRADE). With the PRINT procedure, the BY statement indicates that two separate tables are to be produced, one table for each sex.

  PROC FREQ;
   TABLES GRADE;
   

The third and last procedure used in the sample program is called by the statement PROC FREQ. The FREQ procedure produces frequency tables for the variables listed in the VAR statement. In the example, a table listing the frequency of the grades received is produced.

Discussion

Although the important aspects of SAS programming are detailed above, additional comments are necessary. Following is a brief discussion of three topics about which questions are frequently asked.

Variable Names. SAS variable names are eight characters or less in length. The first character must be a letter A through Z or an underscore (_). The other characters may be a letter A through Z, a number 0 through 9, or an underscore. Blanks or other special characters are not allowed in SAS variable names.

Statement Delimiter. All SAS statements end with a semicolon (;). If it is omitted, SAS reads the next line as part of the current statement. Reading continues until a semicolon is encountered.

Spacing. Spacing is usually not important in SAS programming. Statements may begin in column one or may be indented to indicate the relative importance of the programming statements. The choice is given to the user, and the decision is usually based upon style. Spacing within a statement may also be varied. In general, where one space is allowed, two or more spaces are also permitted.

Sample Program. The sample SAS statements given previously each detail a specific portion of a SAS program. Following is a complete SAS program which incorporates the above examples.

  //GR1234 JOB (1,1234),SMITH,TIME=1,REGION=4096K,CLASS=A
/*ROUTE PRINT SIUCMVSA
//STEP1  EXEC SAS
//SYSIN  DD *
DATA EXAMS;
INPUT @1 NAME $15. @17 SEX $1. @20 AGE 2. @24 DEPT 2.
   @28 GPA 4. @34 SCORE1 3. @39 SCORE2 3. @44 SCORE3 3.;
AVESCORE = MEAN (OF SCORE1-SCORE3);
IF AVESCORE >= 90 THEN GRADE = 'A';
   ELSE IF AVESCORE >= 80 THEN GRADE = 'B';
   ELSE IF AVESCORE >= 70 THEN GRADE = 'C';
   ELSE IF AVESCORE >= 60 THEN GRADE = 'D';
   ELSE GRADE = 'F';
CARDS;
ELIZABETH   F 202 3.2582  93  89
ALAN        M 215 3.7100  89  96
LISA        F 234 3.8492 100  96
MICHAEL     M 223 3.4685  89  91
DAVID       M 191 2.7669  77  85
PROC SORT;
   BY SEX NAME;
PROC PRINT;
   VAR NAME AGE DEPT GRADE;
   BY SEX;
PROC FREQ;
   TABLES GRADE;
/*
//

References

SAS Language and Procedures: Introduction. Version 6. First Edition. SAS Institute, Inc (P56074)
SAS Language and Procedures: Usage. Version 6. First Edition. SAS Institute, Inc (P56075)
SAS Language: Reference. Version 6. First Edition. SAS Institute, Inc (P56076)
SAS Procedures Guide. Version 6. First Edition. SAS Institute, Inc (P56080)
SAS Language and Procedures. Syntax. Version 6. First Edition. SAS Institute, Inc (P56077)
SAS/STAT User's Guide. Version 6. Fourth Edition. SAS Institute, Inc (P56045)
SAS Companion for the MVS Environment: Introduction. Version 6. First Edition. SAS Institute, Inc (P56101)

The above manuals can be ordered from SAS Institute:

SAS Institute, Inc.
Publications Sales Department
Box 8000, SAS Circle
Cary, North Carolina 27511-8000
Telephone: (919) 677-8000