As you discovered in See an overview of SAS, you can use SAS programs to access, manage, analyze, and present your data. The SAS programming language is both powerful and flexible. You can program any number of analyses and reports with it. The SAS language contains statements, expressions, functions and CALL routines, options, formats, and informats–elements that many programming languages share.
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. Base SAS procedures enable you to
- manipulate data
- store and retrieve information
- perform statistical analysis
- create reports.
This task shows you the main characteristics of SAS programs. It also guides you through the basic steps of creating, running, and managing SAS programs and their output.
Components of SAS programs
Let’s begin by looking at a simple SAS program. The sample SAS program below contains two steps: a DATA step and a PROC step. These two types of steps, alone or combined, form all SAS programs.
DATA steps typically create or modify SAS data sets, but they can also be used to produce custom-designed reports. For example, you can use DATA steps to
put your data into a SAS data set
compute the values for new variables
check for and correct errors in your data
produce new SAS data sets by subsetting, merging, and updating existing data sets.
In the sample program, the DATA step creates a new SAS data set ADMIT2 in the CLINIC library using the existing SAS data set ADMIT in the CLINIC library.
PROC (procedure) steps typically analyze and process data in the form of a SAS data set, and they sometimes create SAS data sets that contain the results of the procedure. PROC steps control a library of prewritten routines (procedures) that perform tasks on SAS data sets, such as listing, sorting, and summarizing data. For example, you can use PROC steps to
- print a report
- produce descriptive statistics
- create a tabular report
- produce plots and charts.
The sample program uses the PRINT procedure, which prints the data in a data set. The DATA= option tells SAS what data to use for the procedure.
Characteristics of SAS Programs
Next let’s look at the individual statements in our sample program. SAS programs are made up of SAS statements. A SAS statement has two important characteristics:
- It usually begins with a SAS keyword.
- It always ends with a semicolon.
A DATA step begins with the keyword DATA, and a PROC step begins with the keyword PROC. Generally, a step ends with a RUN statement or when a new DATA or PROC step begins. A RUN statement tells SAS to process all the preceding lines of the step.
SAS statements are free-format. This means that
- they can begin and end anywhere on a line
- one statement can continue over several lines
- several statements can be on a line.
SAS statements are not case sensitive. Blanks or special characters separate the “words” in a SAS statement.
Copy a SAS program into the Editor window
Let’s try running a SAS program that is similar to the sample you just saw. This program creates a new SAS data set from an existing SAS data set and then prints a listing of the new data set.
The Mylib.ProductSales data set was created in Work with SAS data sets. If you didn’t create it, return to the task to define the library and create the data set before proceeding here.
|Submit the program and view output When you submit a SAS program, SAS compiles and executes the code and returns any results to the Results Viewer window.|
|View the logEach time a step is executed, SAS generates a log of the processing activities and the results of the processing. The SAS log collects messages about the processing of SAS programs and any errors that may occur.|