An Introduction To SAS Programming
An Introduction To SAS Programming
An Introduction To SAS Programming
to
SAS
Programming
Center of
Excellence
Agenda
Working with SAS Environment
SAS Programming Basics
Editing and Debugging SAS Programs
Setting up the SAS Session
Creating Basic Reports and Statistics
Objectives
Learn to
Work with and manage your SAS windows
Create SAS libraries
Explore and manage SAS files
Enter and submit SAS programs
Create and use file shortcuts.
Explore Window
User to
Create new libraries and SAS files
Open any SAS file Consolidation of
disparate information sources
Perform most file management tasks such
as moving, copying, and deleting files
Faster time-to-market for products and
services
Create shortcuts to non-SAS files.
Features of Program Editor
Drag and drop SAS Programs on this window
Specify the number of lines to submit at a time
Recall submitted statements
Save contents automatically
Clear contents
Turn line numbers on and off
Use the command line or menus
save your program.
Other Windows’ Features
Log
view messages about your SAS session and
any SAS programs you submit
Output
browse output from SAS programs
Result
navigate and manage output from SAS
programs view, save, and print individual
items of output
Working in SAS
Objectives
The structure and components of SAS
programs
The steps involved in processing SAS programs
The structure and components of SAS data
sets
The two types of SAS data sets
SAS libraries and the types of SAS files that
they contain
Temporary and permanent SAS libraries.
Layout of SAS Programs
SAS Programs used to access, analyze,
manage and present data
SAS Statements
Case insensitive
Free Format
Ends with a semicolon
Styles for Comment - *statement; or /* …*/
Parts of SAS Programs
Data Step
TO CREATE DATA SETS
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.
Proc Step
PROCESS DATA SETS
print a report
produce descriptive statistics
create a tabular report
produce plots and charts.
SAS NAMES (VARIABLES & FILE
NAMES)
NAMES
1 TO 32 CHARACTERS IN LENGTH
START WITH LETTER (A THRU Z) AND _
CAN BE A COMBINATION OF NUMBERS/LETTERS
VARIABLES
CHARACTER
NUMERIC
FILENAMES
2 LEVEL
LIB - WORK/PERMANENT
Editing SAS Programs
the Program Editor window
the Enhanced Editor
the SAS Notepad window
the host editor of your choice
Processing SAS Programs
When you submit a SAS program, SAS software
reads the statements and checks them for errors.
When it encounters a DATA, PROC, or RUN
statement, SAS software stops reading statements
and executes the current step in the program. In
our sample program, each step ends with a RUN
statement.
Example:-
Data Libname.New datasetname;
Set Libname.Old datasetname;
run;
Overview of SAS Data Sets
Conceptually, a SAS data set is a file consisting
of two parts: a descriptor portion and a data
portion. Some SAS data sets also contain an
index, which enables SAS software to locate
records in the data set.
Descriptor Portion
name of the data set
date and time the data set was created
number of observations
number of variables.
each variable's name, type, length, format, informat,
and label.
Data Portion
Data Portion
Tabular Arrangement of data
Contains Observations and Variables
Variables can be either Character or numeric
Character variables can be up to 32K long
Numeric Values stored as floating point
variables have a default length of 8 bytes
SAS can handle up to 32,767 variables
Naming Rules
SAS data set names must
be 1 to 32 characters in length
begin with a letter (A-Z, including mixed case
characters) or an underscore (_)
continue with any combination of numbers,
letters, or underscores.
Example:-
Payroll
Budget1995_1997
_Students
READING RAW DATA
DATA
START
OUTPUT DATA SET
INFILE
POINTER TO EXT FILE
INPUT
HOW TO READ
INPUT @1 DATE $9. @10 BOARDED 3.;
FLAT FILE VARIATIONS (DELIMITERS, LINE
POINTER, LINE HOLD SPECIFIERS)
Variable Formats
SAS Format & Informat
Data Value
Formatted Value
SAS Files
Table
View
Catalog
MDDB
SAS files are stored in a library.
Creating SAS Data Sets
Schedule
Creating Data Sets From Raw Files
Subsetting Data
SAS Functions
Reading Fixed Fields, Free Format files
Reading from files with multiple rows in a single line
Reading from files with a single row in multiple lines
Understanding Data Step Processing
Reading Hierarchical Files
Reading Variable Length Records
Base SAS
data access
management
analysis
presentation
Example
With SAS, we can join Oracle data on a
mainframe computer with an existing SAS
data set, create new variables (columns),
and produce an interactive graph on your
PC.
Types of Files We Can Access
SAS/ACCESS provides access to these types of files:
Relational databases
R/3 SAP BW
Managing Data
After we have accessed relevant data, we
can use the SAS programming language to
manipulate it any way we choose.
For example, we can
format the data
subset data
In some operating environments, a SAS library is a physical collection of files. In others, the
files are only logically related.
Questions