Sunteți pe pagina 1din 27

Introduction to SAS and Basic Concepts

Statistical Analysis System


SAS Presentation | | 7/27/14
2
SAS Presentation | | 7/27/14
3
SAS Presentation | | 7/27/14
5
Turning Data into Information
The process of delivering meaningfl information is typically
distri!ted as
follo"s#

80% data-related
$ access
$ scr!
$ transform
$ manage
$ store and retrieve

20% analysis
SAS Presentation | | 7/27/14
%
SAS Presentation | | 7/27/14
7
SAS Presentation | | 7/27/14
&
Basic concepts of SAS

'vervie"

SAS Programs

SAS (i!raries

)eferencing SAS files

SAS data Sets

*aria!le Attri!tes
SAS Presentation | | 7/27/14
+
Oerie!
To program effectively sing SAS, yo need to nderstand !asic
concepts a!ot SAS programs and the SAS files that they process- .n
particlar, yo need to !e familiar "ith SAS data sets-
SAS Presentation | | 7/27/14
1/
SAS "rogram
0o can se SAS programs to access, manage, analy1e, or present yor
data-
(et2s !egin !y loo3ing at a simple SAS program-
DATA SAMPLE;
INPUT NAME $10.;
DATALINES;
ANIL
ARUN;
RUN;
PROC PRINT DATA=SAMPLE;
RUN;
SAS Presentation | | 7/27/14
11
Components of SAS "rograms # Sample code
'r sample SAS program contains t"o steps# a 4ATA step
and a P)'5 step-
DATA SAMPLE;
INPUT NAME $10.;
DATALINES;
ANIL
ARUN;
RUN;
PROC PRINT DATA=SAMPLE;
RUN;
Continued$
SAS Presentation | | 7/27/14
12
Components of SAS "rograms # DATA ST%"& "'OC ST%"
T(ese t!o types of steps& alone or com)ined& form most SAS programs*
Continued$
SAS Presentation | | 7/27/14
13
DATA steps typically create or modify SAS data sets- They can also !e sed to prodce
cstom designed reports- 6or e7ample, yo can se 4ATA steps to

pt yor data into a SAS data set

compte vales

chec3 for and correct errors in yor data

prodce ne" SAS data sets !y s!setting, merging, and pdating e7isting data sets-
"'OC +procedure, steps are pre8"ritten rotines that ena!le yo to analy1e and
process the data in a SAS data set and to present the data in the form of a report- P)'5
steps sometimes create ne" SAS data sets that contain the reslts of the procedre-
P)'5 steps can list, sort, and smmari1e data- 6or e7ample, yo can se P)'5 steps
to

create a report that lists the data

prodce descriptive statistics

create a smmary report

prodce plots and charts-


Components of SAS "rograms
SAS Presentation | | 7/27/14
14
C(aracteristics of SAS "rograms
9e7t let:s loo3 at the individal statements in or sample program- SAS programs consist
of SAS statements- A SAS statement has t"o important characteristics#

.t sally !egins "ith a SAS -ey!ord-

.t al"ays ends "ith a semicolon


DATA SAMPLE; ---- SAS Data Step creating Dataet
INPUT NAME $10.;
DATALINES;
ANIL
ARUN;
RUN;
PROC PRINT DATA=SAMPLE; -- SAS PROC tep ! Printing DATA
RUN;
SAS Presentation | | 7/27/14
15
.ayout for SAS "rograms
SAS statements are in free format- This means that

they can !egin and end any"here on a line

one statement can contine over several lines

several statements can !e on a line-


;lan3s or special characters separate <"ords< in a SAS
statement-
/ote0 0o can specify SAS statements in ppercase or
lo"ercase- .n most sitations, te7t that is enclosed in
=otation mar3s is case sensitive-
SAS Presentation | | 7/27/14
1%
"rocessing SAS "rograms
>hen yo s!mit a SAS program, SAS !egins reading the statements and chec3ing
them for errors- 4ATA and P)'5 statements signal the !eginning of a ne" step- >hen
SAS enconters a s!se=ent 4ATA, P)'5, or )?9 statement @for 4ATA steps and
most procedresA or a B?.T statement @for some procedresA, SAS stops reading
statements and e7ectes the previos step in the program- .n or sample program, each
step ends "ith a )?9 statement-
DATA SAMPLE; ---- SAS Data Step creating Dataet
INPUT NAME $10.;
DATALINES;
ANIL
ARUN;
RUN;
PROC PRINT DATA=SAMPLE; -- SAS PROC tep ! Printing DATA
RUN;
/ote0 The !eginning of a ne" step @4ATA or P)'5A implies the end of the previos
step- Thogh the )?9 statement is not al"ays re=ired !et"een steps in a
SAS program, sing it can ma3e the SAS program easier to read and de!g,
and it ma3es the SAS log easier to read-
SAS Presentation | | 7/27/14
17
.og 1essages
Cach time a step is e7ected, SAS generates a log of the processing activities and the reslts of the
processing- The SAS log collects messages a!ot the processing of SAS programs and a!ot any errors
that occr- >hen SAS processes or sample program, yo see the log messages sho"n !elo"- 9otice that
yo get separate sets of messages for each step in the program-
SAS .og0
SAS Presentation | | 7/27/14
1&
SAS .og and SAS .i)raries
Cvery SAS file is stored in a SAS li)rary, "hich is a collection of SAS files- A
SAS data li!rary is the highest level of organi1ation for information "ithin SAS-
6or e7ample, in the >indo"s and ?9.D environments, a li!rary is typically a
grop of SAS files in the same folder or directory-
SAS Presentation | | 7/27/14
1+
SAS .i)raries
The ta!le !elo" smmari1es the implementation of SAS li!raries in varios
operating environments-
SAS Presentation | | 7/27/14
2/
'eferencing SAS 2iles

To reference a SAS file, yo se a t"o8level name,


libref.filename- .n the t"o8level name, libref is the name for
the SAS li!rary that contains the file, and filename is the name of the
file itself- A period separates the li!ref and filename-

To reference temporary SAS files, yo specify the defalt li!ref 3or-,


a period, and the filename- Alternatively, yo can simply se a one8
level name @the filename onlyA to reference a file in a temporary SAS
li!rary- )eferencing a SAS file in any li!rary e4cept 3or- indicates
that the SAS file is stored permanently-

SAS data set names can !e 1 to 32 characters long, mst !egin "ith
a letter @A-E, either ppercase or lo"ercaseA or an nderscore @FA,
and can contine "ith any com!ination of nm!ers, letters, or
nderscores-
SAS Presentation | | 7/27/14
21
SAS Data Sets

6or many of the data processing tas3s that yo perform "ith


SAS, yo access data in the form of a SAS data set and
se SAS programs to analy1e, manage, or present the data-
5onceptally, a SAS data set is a file that consists of t"o
parts# a descriptor portion and a data portion-

The descriptor portion of a SAS data set contains information a!ot the data set-

The data portion of a SAS data set is a collection of data vales that are arranged in a
rectanglar ta!le-
O)serations in the data set correspond to ro"s or data lines in a ra" data file
or in an e7ternal data!ase- An o!servation is the information a!ot each o!Gect in a SAS
data set-
5aria)les in the data set correspond to colmns in a ra" data file or in an e7ternal
data!ase-
SAS Presentation | | 7/27/14
22
5aria)le Attri)utes

.n addition to general information a!ot the data set, the descriptor


portion contains information a!ot the attri!tes of each varia!le in
the data set- The attri!te information incldes the

varia!le:s name,

type,

length,

format,

informat, and

la!el-
/ame

Cach varia!le has a name that conforms to SAS naming conventions- *aria!le names
follo" e7actly the same rles as SAS data set names- (i3e data set names, varia!le
names

can !e 1 to 32 characters long

mst !egin "ith a letter @A-E, either ppercase or lo"ercaseA or an nderscore @FA

can contine "ith any com!ination of nm!ers, letters, or nderscores-


Continued$
SAS Presentation | | 7/27/14
23
5aria)le Attri)utes
9ame continedH
Type
A varia!le:s type is either c(aracter or numeric-
5haracter varia!les, sch as 9ame @sho"n !elo"A, can contain any alues-
9meric varia!les, sch as Policy and Total @sho"n !elo"A, can contain only numeric alues @the digits / throgh +, I, 8, -, and C for
scientific notationA-
Continued$
SAS Presentation | | 7/27/14
24
.engt(
A varia!le:s lengt( @the nm!er of !ytes
sed to store itA is related to its type-

5haracter varia!les can !e p to 62&787 )ytes long- .n the e7ample !elo", 9ame
has a length of 2/ characters and ses 2/ !ytes of storage-

All nmeric varia!les have a defalt length of 8- 9meric vales @no matter ho"
many digits they containA are stored as floating8point nm!ers in & !ytes of storage,
nless yo specify a different length-
5aria)le Attri)utes
Continued$
SAS Presentation | | 7/27/14
25
5aria)le Attri)utes
2ormat

6ormats are varia!le attri!tes that affect the "ay data vales are "ritten- SAS
soft"are offers a variety of character, nmeric, and date and time formats- 0o
can also create and store yor o"n formats- To "rite vales ot sing a
particlar form, yo select the appropriate format-
Continued$
SAS Presentation | | 7/27/14
2%
5aria)le Attri)utes
Informat

2ormats "rite vales out !y sing some particlar form "hereas informats read data vales in
certain forms into standard SAS vales- .nformats determine ho" data vales are read into a SAS
data set- 0o must se informats to read nmeric vales that contain letters or other special
characters-
Continued$
SAS Presentation | | 7/27/14
27
5aria)le Attri)utes
.a)el

A varia!le can have a la)el, "hich consists of descriptive


te7t p to 25% characters long- ;y defalt, many reports
identify varia!les !y their names- 0o might "ant to display
more descriptive information a!ot the varia!le !y
assigning a la!el to the varia!le-
SAS Presentation | | 7/27/14
2& 2&

S-ar putea să vă placă și