Appendix C: SAS Software - PowerPoint PPT Presentation

About This Presentation
Title:

Appendix C: SAS Software

Description:

Appendix C: SAS Software Uses of SAS linear programming forecasting econometrics nonlinear parameter estimation CRM datamining data warehousing simulation – PowerPoint PPT presentation

Number of Views:101
Avg rating:3.0/5.0
Slides: 34
Provided by: CharlesF71
Category:

less

Transcript and Presenter's Notes

Title: Appendix C: SAS Software


1
Appendix C SAS Software
Uses of SAS
  • linear programming
  • forecasting
  • econometrics
  • nonlinear parameter estimation
  • CRM
  • datamining
  • data warehousing
  • simulation
  • marketing models
  • statistical analysis

Data Types SAS Can Deal with
  • Web log data
  • questionnaires
  • panel data
  • relational databases
  • scanner data

Ideal When You Are
  • massaging
  • sorting
  • merging
  • lookups
  • reporting
  • transforming
  • manipulating

2
Two Types of SAS Routines
  • DATA Steps
  • Read and Write Data
  • Create a SAS dataset
  • Manipulate and Transform Data
  • Open-Ended - Procedural Language
  • Presence of INPUT statement creates a Loop
  • PROC Steps
  • Analyze Data
  • Canned or Preprogrammed Input and Output

3
A Simple Example
  • data my_study
  • input id gender green recycle
  • cards
  • 001 m 4 2
  • 002 m 3 1
  • 003 f 3 2
  • proc reg datamy_study
  • class gender
  • model recycle green gender

4
The Sequence Depends on the Need
  • data step to read in scanner data
  • data step to read in panel data
  • data step to merge scanner and panel records
  • data step to change the level of analysis to the
    household
  • proc step to create covariance matrix
  • data step to write covariance matrix in LISREL
    compatable format

5
The INPUT Statement - Character Data
  • List input
  • after a variable - character var
  • input last_name first_name initial
  • Formatted input
  • w. after a variable
  • input last_name 22. first_name 22. initial
    1.
  • Column input
  • start-column - end-column
  • input last_name 1 - 22 first_name 23 - 45
    initial 46

6
The INPUT Statement - Numeric Data
  • List input
  • input score_1 score_2 score_3
  • Formatted input
  • w.d (field width and number of digits after an
    implied decimal point) after a variable
  • input score_1 10. score_2 10. score_3 10.
  • Column input
  • start-column - end-column
  • input score_1 1 - 10 score_2 11 - 20 score_3 21
    - 30

7
Grouped INPUT Statements
  • input (var1-var3) (10. 10. 10.)
  • input (var1-var3) (310.)
  • input (var1-var3) (10.)
  • input (name var1-var3) (10. 35.1)

8
The Column Pointer in the INPUT Statement
  • input _at_3 var1 10.
  • input more _at_
  • if more then input _at_15 x1 x2
  • input _at_12 x1 5. 3 x2

9
Documenting INPUT Statements
  • input _at_4 green1 4. / greeness scale
    first item /
  • _at_9 green2 4. / greeness scale 2nd
    item /
  • _at_20 aware1 5. / awareness scale
    first item /
  • _at_20 aware2 5. / awareness scale
    2nd item /

10
The Line Pointer
  • input x1 x2 x3 / x4 x4 x6
  • input x1 x2 x3 2 x4 x5 x6
  • input x1 x2 x3
  • 2 x4 x5 x6

11
Reading an External File on Unix
  • data
  • filename raw_sem 'my_garnet_disk_file.data'
  • infile raw_sem
  • input a b etc.

12
The PUT Statement
  • put _all_
  • put a b
  • put _infile_
  • put _page_
  • col1 22 col2 14
  • put _at_col1 var245 _at_col2 var246
  • put x1 x2 x3 _at_
  • input x4
  • put x4
  • put x1 2 x2
  • put x1 / x2

13
Copying Raw Data
  • data _null_
  • infile in
  • outfile out
  • input
  • put _infile_

14
SAS Constants
  • '21Dec1981'D
  • 'Charles F. Hofacker'
  • 492992.1223

15
Assignment Statement
  • x a b
  • y x / 2.
  • prob 1 - exp(-z2/2)

16
The SAS Array Statement
  • array y 20 y1-y20
  • do i 1 to 20
  • yi 11 - yi
  • end

17
The Sum Statement
  • variableexpression

retain variable variable variable
expression
n1 cumulated x
18
IF Statement
  • if a gt 45 then a 45
  • if 0 lt age lt 1 then age 1
  • if a 2 or b 3 then c 1
  • if a 2 and b 3 then c 1
  • if major "FIN"
  • if major "FIN" then do
  • a 1
  • b 2
  • end

19
More IF Statement Expressions
  • name ne 'smith'
  • name 'smith'
  • x eq 1 or x eq 2
  • x1 x2
  • a lt b a gt c
  • a le b or a le c
  • a1 and a2 or a3
  • (a1 and a2) or a3

if
then etc
20
Concatenating Datasets Sequentially
first id x y 1 2 3 2 1 2 3 3 1
second id x y 4 3 2 5 2 1 6 1 1
  • data both
  • set first second

both id x y 1 2 3 2 1 2 3 3 1 4 3 2 5 2
1 6 1 1
21
Interleaving Two Datasets
  • proc sort datastore1
  • by date
  • proc sort datastore2
  • by date
  • data both
  • set store1 store2
  • by date

22
Concatenating Datasets Horizontally
left id y1 y2 1 2 3 2 1 2 3 3 1
right id x1 x2 1 3 2 2 2 1 3 1 1
  • data both
  • merge left right

both id y1 y2 x1 x2 1 2 3 3 2 2 1 2 2
1 3 3 1 1 1
23
Table LookUp
table part desc 0011 hammer 0012 nail 0013
bow
database id part 1 0011 2 0011 3 0013
  • proc sort datadatabase outsorted
  • by part
  • data both
  • merge table sorted
  • by part

both id part desc 1 0011 hammer 2 0011
hammer 3 0013 bow
24
Changing the Level of Analysis 1
  • Day Score Student
  • 1 12 A
  • 1 11 B
  • 1 13 C
  • 2 14 A
  • 2 10 B
  • 2 9 C
  • Day Highest Student
  • 1 13 C
  • 2 14 A

Before
After
25
Changing the Level of Analysis 1FIRST. and LAST.
Variable Modifiers
  • proc sort datalog
  • by day
  • data find_highest
  • retain hightest
  • drop score
  • set log
  • by day
  • if first.day then highest.
  • if score gt highest then highest score
  • if lastday then output

26
Changing the Level of Analysis 2
  • Subject Time Score
  • A 1 A1
  • A 2 A2
  • A 3 A3
  • B 1 B1
  • B 2 B2
  • B 3 B3
  • Subject Score1 Score2 Score3
  • A A1 A2 A3
  • B B1 B2 B3

Before
After
27
Changing the Level of Analysis 2
  • data after
  • keep subject score1 score2 score3
  • retain score1 score2
  • set before
  • if time1 then score1 score
  • else if time2 then score2 score
  • else if time3 then do
  • score3 score
  • output
  • end

28
The KEEP and DROP Statements
  • keep a b f h
  • drop x1-x99
  • data a(keep a1 a2) b(keep b1 b2)
  • set x
  • if blah then output a
  • else output b

29
Changing the Level of Analysis 3Spreading Out an
Observation
  • Subject Score1 Score2 Score3
  • A A1 A2 A3
  • B B1 B2 B3
  • Subject Time Score
  • A 1 A1
  • A 2 A2
  • A 3 A3
  • B 1 B1
  • B 2 B2
  • B 3 B3

Before
After
30
Code for Change 3
  • data spread
  • drop score1 score2 score3
  • set tight
  • time 1 score score1 output
  • time 2 score score2 output
  • time 3 score score3 output

31
Use of the IN Dataset Indicator
  • data new
  • set old1 (infrom_old1)
  • old2 (infrom_old2)
  • if from_old1 then
  • if from_old2 then

32
Proc Summary for Aggregation
  • proc summary dataraw_purchases
  • by household
  • class brand
  • output outhousehold countx xy
  • VAR variable(s)lt/ WEIGHTweight-variablegt

33
Using SAS for Simulations
  • data monte_carlo
  • keep y1 - y4
  • array y4 y1 - y4
  • array loading4 l1 - l4
  • array unique4 u1 - u4
  • l1 1 l2 .5 l3 .5 l4 .5
  • u1 .2 u2 .2 u3 .2 u4 .2
  • do subject 1 to 100
  • eta rannor(1921)
  • do j 1 to 4
  • yj etaloadingj
    uniquejrannor(2917)
  • end
  • output
  • end
  • proc calis datamonte_carlo
  • etc.

Simulation Loop
Write a Comment
User Comments (0)
About PowerShow.com