What Is the SAS System? |
Overview of Base SAS Software |
Base SAS software contains the following:
Learning to use Base SAS enables you to work with these features of SAS. It also prepares you to learn other SAS products, because all SAS products follow the same basic rules.Data Management Facility |
SAS organizes data into a rectangular form or table that is called a SAS data set. The following figure shows a SAS data set. The data describes participants in a 16-week weight program at a health and fitness club. The data for each participant includes an identification number, name, team name, and weight (in U.S. pounds) at the beginning and end of the program.
Rectangular Form of a SAS Data Set
In a SAS data set, each row represents information about an individual entity and is called an observation. Each column represents the same type of information and is called a variable. Each separate piece of information is a data value. In a SAS data set, an observation contains all the data values for an entity; a variable contains the same type of data value for all entities.
To build a SAS data set with Base SAS, you write a program that uses statements in the SAS programming language. A SAS program that begins with a DATA statement and typically creates a SAS data set or a report is called a DATA step.
The following SAS program creates a SAS data set named WEIGHT_CLUB from the health club data:
data weight_club; 1 input IdNumber 1-4 Name $ 6-24 Team $ StartWeight EndWeight; 2 Loss=StartWeight-EndWeight; 3 datalines; 4 1023 David Shaw red 189 165 5 1049 Amelia Serrano yellow 145 124 5 1219 Alan Nance red 210 192 5 1246 Ravi Sinha yellow 194 177 5 1078 Ashley McKnight red 127 118 5 ; 6 run;
The following list corresponds to the numbered items in the preceding program:
Note: By default, the data set WEIGHT_CLUB is temporary; that is, it exists only for the current job or session. For information about how to create a permanent SAS data set, see Introduction to DATA Step Processing.
Programming Language |
The statements that created the data set WEIGHT_CLUB are part of the SAS programming language. The SAS language contains statements, expressions, functions and CALL routines, options, formats, and informats - elements that many programming languages share. However, the way you use the elements of the SAS language depends on certain programming rules. The most important rules are listed in the next two sections.
The conventions that are shown in the programs in this documentation, such as indenting of subordinate statements, extra spacing, and blank lines, are for the purpose of clarity and ease of use. They are not required by SAS. There are only a few rules for writing SAS statements:
You can enter SAS statements in lowercase, uppercase, or a mixture of the two.
You can begin SAS statements in any column of a line and write several statements on the same line.
You can begin a statement on one line and continue it on another line, but you cannot split a word between two lines.
Words in SAS statements are separated by blanks or by special characters (such as the equal sign and the minus sign in the calculation of the Loss variable in the WEIGHT_CLUB example).
SAS names are used for SAS data set names, variable names, and other items. The following rules apply:
For variable names only, SAS remembers the combination of uppercase and lowercase letters that you use when you create the variable name. Internally, the case of letters does not matter. "CAT," "cat," and "Cat" all represent the same variable. But for presentation purposes, SAS remembers the initial case of each letter and uses it to represent the variable name when printing it.
Data Analysis and Reporting Utilities |
The SAS programming language is both powerful and flexible. You can program any number of analyses and reports with it. SAS can also simplify programming for you with its library of built-in programs known as SAS procedures. SAS procedures use data values from SAS data sets to produce preprogrammed reports, requiring minimal effort from you.
For example, the following SAS program produces a report that displays the values of the variables in the SAS data set WEIGHT_CLUB. Weight values are presented in U.S. pounds.
options linesize=80 pagesize=60 pageno=1 nodate; proc print data=weight_club; title 'Health Club Data'; run;
This procedure, known as the PRINT procedure, displays the variables in a simple, organized form. The following output shows the results:
Displaying the Values in a SAS Data Set
Health Club Data 1 Id Start End Obs Number Name Team Weight Weight Loss 1 1023 David Shaw red 189 165 24 2 1049 Amelia Serrano yellow 145 124 21 3 1219 Alan Nance red 210 192 18 4 1246 Ravi Sinha yellow 194 177 17 5 1078 Ashley McKnight red 127 118 9To produce a table showing mean starting weight, ending weight, and weight loss for each team, use the TABULATE procedure.
options linesize=80 pagesize=60 pageno=1 nodate; proc tabulate data=weight_club; class team; var StartWeight EndWeight Loss; table team, mean*(StartWeight EndWeight Loss); title 'Mean Starting Weight, Ending Weight,'; title2 'and Weight Loss'; run;
The following output shows the results:
Table of Mean Values for Each Team
Mean Starting Weight, Ending Weight, 1 and Weight Loss ----------------------------------------------------------- | | Mean | | |--------------------------------------| | |StartWeight | EndWeight | Loss | |------------------+------------+------------+------------| |Team | | | | |------------------| | | | |red | 175.33| 158.33| 17.00| |------------------+------------+------------+------------| |yellow | 169.50| 150.50| 19.00| -----------------------------------------------------------A portion of a SAS program that begins with a PROC (procedure) statement and ends with a RUN statement (or is ended by another PROC or DATA statement) is called a PROC step. Both of the PROC steps that create the previous two outputs comprise the following elements:
a PROC statement, which includes the word PROC, the name of the procedure you want to use, and the name of the SAS data set that contains the values. (If you omit the DATA= option and data set name, the procedure uses the SAS data set that was most recently created in the program.)
additional statements that give SAS more information about what you want to do, for example, the CLASS, VAR, TABLE, and TITLE statements.
a RUN statement, which indicates that the preceding group of statements is ready to be executed.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.