The Goal
SAS Base is a very versatile and flexible programming environment. Our goal is to
learn SAS at a level that we can conduct Survival Analysis.
Also, to provide the students with a crash course for the basic understanding of SAS
Base environment
SAS is short for Statistical Analysis System. The company dropped the longer name
once the abbreviation, SAS, became more common than the original one.
Section 1
SAS LANGUAGE
SAS programs
Many software applications are either menu driven, or command driven (enter a
command - see the result)
SAS is a statement-driven language. You use a list of statements as instructions to
write SAS programs.
SAS Enterprise Guide or SAS JMP are point-and-click environments for writing SAS
programs but they don't offer the flexibility of Base SAS.
You first say what you want to do, then give all the information teller needs.
The order of the details may change, but what you want to do must be always the
first.
Very important:
Every SAS statement ends with a semicolon (;).
Firstruleistherearentmanysyntaxrules.Theonlyrealrule
iseverystatementendswithasemicolon.
Thesyntaxandformatareveryflexible.
Itisnotcasesensitive.
Statementscancontinueonthenextline.Also,therecanbe
morethanonestatementononeline.
Statementscanstartonanycolumnofthetexteditor.
SinceSASisthisflexible,itiseasytowriteSAScodethat
cannotberecognizedevenbythecoder.Weneedtobetidyand
organized:
Useindention
Usenamingconvention
Usecasingconvention(partofnamingconvention)
Use the same rules in the same code, even in your career if possible.
numPrice, numPrice_Toys, numPrice_Hotel_Stay
charName, charName_City, charName_Baseball_Team
name, nameCity, nameBaseballTeam
calories_sugar, fiber_sugar, protein_sugar
a = b * c, instead write
discountAmount = priceItem * discountPercentage
Section 2
Observation
(also called rows)
ID
Name
Height
Weight
53
Susie
42
41
54
Charlie
46
55
55
Calvin
40
35
56
Lucy
46
52
57
Dennis
44
43
50
58
Data point (or cell) Calvin shows the value for the 3rd observation and second
variable Name.
Data Types
ID
Name
Height
Weight
53
Susie
42
41
54
Charlie
46
55
55
Calvin
40
35
56
Lucy
46
52
57
Dennis
44
43
50
58
Using naming conventions can make your life easier if a need for debugging or
returning back to your code arises.
Section 3
An Example
DATA Step
PROC Step
DATA distance;
Miles = 26.22;
Kilometers = 1.61 * Miles;
RUN;
PROC PRINT DATA = distance;
RUN;
Common Properties of
SAS Programs
Different Characteristics
DATA Steps
PROC Steps
You dont need to tell SAS to execute this loop. It is handled automatically as
opposed to many coding languages. It is like T-SQL in that sense more than C#.
Section 4
Libraries
Before you can use a SAS data set, you have to tell SAS where to find it by setting up
a SAS library.
A SAS library is simply a location where SAS data sets are stored. It is like an
address or a reference for a physical storage unit.
Ways to set up a library:
Using LIBNAME statement
Using New Library window
You can navigate libraries using the Explorer window.
Libraries on Start-up
SASHELP
SASUSER
WORK:
It is the default library
It is the temporary storage location for SAS datasets.
All data in this library is deleted once you end you SAS session.
Other Functions