Lab 1 - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Lab 1

Description:

Lab 1. Introduction to SAS. Getting Started. Open use labs or ... Data you input yellow. Comments green (put '*' before and ';' after for comments) ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 19
Provided by: MichaelB195
Category:
Tags: lab

less

Transcript and Presenter's Notes

Title: Lab 1


1
Lab 1
  • Introduction to SAS

2
Getting Started
  • Open use labs or bookstore
  • SAS windows
  • Program (editor) Window
  • Log Window (info about your program)
  • Output Window (results)
  • Help

3
Example Program Editor
DATA D1 INPUT A 1 B 3 CARDS 1 2 2 2 2 3 3 4 2
3 1 3 2 1 1 2 4 4 2 2 PROC print RUN
Data Step (cannot be more than 8 characters and
begins with a letter)
SAS Grammar the semicolon.
Data
Data and Proc steps.
Proc Step
4
Program Editor Notes
  • Functions
  • Describe data
  • Manipulate data
  • Tell SAS what analysis you want
  • All caps and indent, makes it easier to read
  • Color codes are helpful (8.0), watch out for red
  • DATA, Run, and PROC statements dark blue
  • Other SAS commands, ex. infile, cards royal
    blue
  • Options, variable names, ect black
  • Data you input yellow
  • Comments green (put before and after
    for comments)
  • SAS doesnt recognize red

5
Program Editor (Cont.)
  • OPTIONS LINESIZE80 PAGESIZE60 NODATE
  • Linesize must be between 64 and 256
  • Recall last submit button if you want to get
    the program you just entered back. (Run menu)
  • Write stream of numbers at top so you can tell
    what column you are in and then erase it before
    you run it.
  • 123456789012345678901234567890

6
Example Log with no errors
  • 292 DATA D1
  • 293 INPUT A 1 B 3
  • 294 CARDS
  • NOTE The data set WORK.D1 has 10 observations
    and 2 variables.
  • NOTE DATA statement used
  • real time 0.04 seconds
  • 305 PROC PRINT
  • 306 RUN
  • NOTE There were 10 observations read from the
    data set WORK.D1.
  • NOTE PROCEDURE PRINT used
  • real time 0.11 seconds

7
Example Log with error
  • 501 DATA D1
  • 502 INPUT A 1 b 3
  • NOTE SCL source line.
  • 503 1 2
  • -
  • 180
  • ERROR 180-322 Statement is not valid or it is
    used out of proper order.
  • 513
  • ERROR No CARDS or INFILE statement.
  • NOTE The SAS System stopped processing this step
    because of errors.
  • WARNING The data set WORK.D1 may be incomplete.
    When this step was stopped there were 0
  • observations and 2 variables.
  • WARNING Data set WORK.D1 was not replaced
    because this step was stopped.
  • NOTE DATA statement used
  • real time 0.11 seconds
  • 514 PROC print

8
Notes on Log
  • Always check log. Look for red (errors) and
    green (warnings) writing.
  • Blue writing is providing you with information.
  • You can make errors that wont show on your log.
  • Always do a proc print statement to make sure you
    inputted your data correctly.
  • If there are errors, look for missing first.
  • You can clear your log and output new button.

9
Example Output
  • The SAS System 1516 Monday, January 6,
    2003 37
  • Obs
    A
  • 1
    1
  • 2
    2
  • 3
    2
  • 4
    3
  • 5
    2
  • 6
    1
  • 7
    2
  • 8
    1
  • 9
    4
  • 10
    2

10
Describe how to read data
  • Input X read numbers and assign them to a
    variable called X
  • Data manipulation, variable creation, simple
    computation
  • Input X input a variable called X
  • Y X 2 create Y by adding 2 to X
  • Cards data go next , right after cards

11
Input Statement
  • Free format (blank space represents new variable)
  • Input X Y Z A1 A2 A3
  • Easy but problem with missing data
  • Example
  • 1 2 3 4 5 6
  • 1 2 3 4 5 6
  • Problem comes when
  • 1 2 4 5 6
  • 1 3 4 5 6
  • Solve problem with
  • 1 2 . 4 5 6
  • 1 . 3 4 5 6

12
Input Statement (2)
  • Column Format
  • Input A 1 B 2-3 C 10-15
  • Alpha variables () Input Name 1-20
  • Pointing (_at_) Input Name 1-20 _at_23 A2
  • Record Number () Input Name 1-20 2 SSN
    21-29
  • Example Susan Smith
  • 555123456
  • Tim Smith
  • 555234567

13
Input Statement (3)
  • Fixed format (informat).
  • Input Name 1-10 A1 11 A2 12 A3 13
  • Input Name 1-10 (A1-A3)(1.0)
  • 1234567890123
  • Barney 523
  • Input Name 1-10 (A4-A5)(5.2)
  • 12345678901234567890
  • Barney 52356 2345

14
Input Statement (4)
  • Combining formats
  • SAS allows mixing different formats, e.g.,
  • Input A1 14 _at_50 (T1-T10)(1.0) _at_70 S1
  • CARDS statement
  • Data D1 Input X Y CARDS data
  • INFILE statement
  • Data D1
  • INFILE C\My Documents\SASfiles\stuff.dat
  • Input X Y Z PROC Print

Note that INFILE goes BEFORE INPUT but CARDS goes
AFTER INPUT.
15
Recoding
  • Create an array to recode
  • ARRAY A I4 I5 I6
  • DO OVER A
  • A 6A
  • END
  • This is an Array called A. It has three items
    and it is taking each item in the array and
    subtracting it from 6.
  • You want to include this statement between your
    input and cards statements.

16
Arithmetic Operations
  • Addition
  • Subtraction -
  • Multiplication
  • Division /
  • Power (exponent)
  • Example
  • Scale A1 A2 A3
  • Scale Sum(of A1-A3) Ignores missing
    values.

17
Notes on Homework Assignments
  • Due at the beginning of each class. Drop box or
    e-mail electronic information.
  • I recommend that you copy and paste your output
    into a word file so that you can edit and shrink
    it down.

18
SAS example
  • Example
  • Col 1-4 Birthdate
  • Col 6 Sex 0M, 1F
  • Col 8 Number of siblings
  • Data
  • 1953 0 3
  • 1966 1 3
  • 1973 0 0
Write a Comment
User Comments (0)
About PowerShow.com