Download presentation
Published byStanley Stevenson Modified over 8 years ago
1
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
By Tasha Chapman, Oregon Health Authority
2
About these trainings
3
What is SAS? Began as a statistical package Also allows users to:
Store data Manipulate data Create reports PDF Excel HTML XML RTF / Word Etc. Etc. Etc.
4
What is SAS? Also allows users to: Create graphs Create maps
Send s Create web applications Create iPhone Apps Access R Schedule regularly run reports Etc. Etc. Etc.
5
About these trainings Created by Tasha Chapman
Originally held in early 2013 Examples created using SAS version 9.2
6
About these trainings Material based on Learning SAS by Example: A Programmer’s Guide by Ron Cody Book is available for state employees using Books 24x7 through the Oregon State Library Sample code and data files from the book can be found: Some slides will have a book icon at the corner of the slide with a hyperlink to additional text
7
Training schedule Basic Data Manipulation Week 1: Chapters 1 & 2
Introduction to SAS Week 2: Chapters 3 & 4 (except 3.9 through 3.14) Creating permanent SAS datasets SAS Libraries Reading raw data from external files Proc Print / Proc Contents
8
Training schedule Basic Data Manipulation (cont.)
Week 3: Chapters 5 & 6 (and 3.9 through 3.14) Creating formats and labels Reading and writing data from an Excel spreadsheet Proc Import with a twist Proc Datasets Week 4: Chapters 7 & 10 (except 10.6, 10.13) Conditional processing Subsetting and combining SAS datasets
9
Training schedule Basic Data Manipulation (cont.)
Week 5: Chapters 9, 11, & 12 (and 10.13) Working with dates About SAS Date, Time, and Datetime values Anydate informat Working with numeric functions Working with character functions Put and Input
10
Training schedule Basic Reporting Week 6: Chapters 14 & 19
Displaying your data (PROC Print) Global statements (titles, footnotes, system options) Introducing the Output Delivery System Week 7: Chapters 16 & 17 (and 10.6) Summarizing your data (PROC Means) Counting frequencies (PROC Freq)
11
Training schedule Basic Reporting (cont.) Week 8: Chapter 15
Creating customized reports (PROC Report) Week 9: Chapter 18 Creating Tabular Reports (PROC Tabulate)
12
Training schedule Advanced Topics Week 10: Chapter 26
Introduction to SQL Week 11: Chapters 8, 13 & 24 Iterative processing and looping Working with multiple observations per subject By group processing Working with arrays
13
Training schedule Advanced Topics (cont.) Week 12: Chapter 25
Introduction to SAS Macro Language %LET CALL SYMPUT Week 13: Chapter 20 Generating high quality graphics
14
Training schedule Advanced Topics (cont.)
Week 14: Chapters 21, 22 & 23 The Leftovers! Restructuring SAS datasets (PROC Transpose) Using advanced features of user-defined formats and informats Using advanced input techniques Saving and storing macros
15
SAS Display Manager
16
Details about jobs you’ve run, including error messages
Log: Details about jobs you’ve run, including error messages Explorer Window: See libraries and SAS datasets Enhanced Editor: Where you write your SAS code
17
List of previously run results
Results tab: List of previously run results Output Window: Basic view of results and output (Also known as “Listing Destination”)
18
Run: Submits your SAS code (“The Running Man”)
19
You can submit the program as a whole
or Run only a portion of highlighted code
20
Chunks of code will be processed in the order you RUN them, not necessarily in the order you wrote them
21
The elements of a SAS program
22
Read and write data, manipulate data, perform calculations, etc.
DATA steps: Read and write data, manipulate data, perform calculations, etc. Every DATA step creates a new dataset
23
Every SAS program can have multiple DATA and PROC steps
Produce reports, summarize data, sort data, create formats, generate graphs, etc. etc. etc.
24
Titles, Footnotes, Options, Macros, Libname
Global statements: Remain in effect until changed by another global statement or SAS session ends Examples: Titles, Footnotes, Options, Macros, Libname
25
/* comment statement */
Comment statements: Ignored by SAS when code is run Used to write comments to yourself or others or comment out code you don’t want to run *comment statement; or /* comment statement */
26
Programming in SAS SAS is generally forgiving
Code can be written on a single line or multiple lines Code and variable names not case sensitive Even accepts some misspellings Fi The Doo Semicolons are super important Colors of Enhanced Editor Always check your log!!! Often many ways to do the same thing
27
DATA step examples
28
DATA step examples
29
DATA step examples DATA demographic
“DATA demographic” creates a dataset called “Demographic” Infile statement reads the text file with the data Input statement tells SAS what to name the new variables. $ sign after “Gender” indicates that this is a character variable. The remaining variables are numeric.
30
DATA step examples DATA newdemo
“DATA newdemo” creates a dataset called “newdemo” “SET demographic” references the previous dataset “demographic” as the basis for the new dataset “BMI =” creates a new variable called “BMI” that is calculated as shown. This is called an assignment statement.
31
PROC step examples
32
PROC step examples
33
PROC step examples PROC freq Creates a basic frequency table with:
Percent Cumulative Frequency Cumulative Percent “DATA=newdemo” references the newdemo dataset TABLE statement indicates which variable(s) to include Can use multiple variables and even create cross-tab tables
34
PROC step examples PROC means Creates a basic summary table with: N
Std Dev Minimum Maximum Can specify which statistics to use in table “DATA=newdemo” references the newdemo dataset VAR statement indicates which variable(s) to include
35
Good SAS programmers use EXPLICIT step boundaries
Other notes Step boundaries: Each step is executed when a step boundary is encountered Explicit step boundary: RUN or QUIT statement Implicit step boundary: Beginning of a new PROC or DATA step Good SAS programmers use EXPLICIT step boundaries
36
Good SAS programmers use EXPLICIT dataset references
Other notes Referencing datasets: Most procedures and DATA steps reference an existing dataset Explicit dataset reference: DATA= or SET statement Implicit dataset reference: If not explicitly referenced, SAS will use the last referenced dataset Good SAS programmers use EXPLICIT dataset references
37
SAS Help
38
Where to learn more about SAS
Technical papers SAS User Groups Websites Books Classes Learning_SAS_-_Resources_You_Can’t_Live_Without Popular Websites
39
Popular Websites
40
Popular Websites
41
www.ats.ucla.edu/stat/sas Explains both the stats and the SAS code
Popular Websites
42
Popular Websites
43
SAS Help and Documentation
Popular Websites
44
How to read SAS Documentation
DATA output-SAS-data-set (DROP=variable(s) | KEEP=variable(s)); SET SAS-data-set <options>; BY variable(s); RUN;
45
How to read SAS Documentation
DATA output-SAS-data-set (DROP=variable(s) | KEEP=variable(s)); SET SAS-data-set <options>; BY variable(s); RUN; DATA, DROP=, KEEP=, SET, BY, and RUN are in uppercase bold because they must be spelled as shown.
46
How to read SAS Documentation
DATA output-SAS-data-set (DROP=variable(s) | KEEP=variable(s)); SET SAS-data-set <options>; BY variable(s); RUN; output-SAS-data-set, variable(s), SAS-data-set, and options are in italics because each represents a value that you supply.
47
How to read SAS Documentation
DATA output-SAS-data-set (DROP=variable(s) | KEEP=variable(s)); SET SAS-data-set <options>; BY variable(s); RUN; <options> is enclosed in angle brackets because it is optional syntax.
48
How to read SAS Documentation
DATA output-SAS-data-set (DROP=variable(s) | KEEP=variable(s)); SET SAS-data-set <options>; BY variable(s); RUN; DROP= and KEEP= are separated by a vertical bar ( | ) to indicate that they are mutually exclusive.
49
Sample datasets
50
R:\Training\SAS\Learning SAS by Example (Cody)\60864
Original zip file in: R:\Training\SAS\Learning SAS by Example (Cody)\60864
51
Permanent location of all SAS Datasets
Text and CSV: Text and CSV data files used to create the SAS Datasets
52
For next week… Read chapters 3 & 4 (skip sections 3.9 through 3.14)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.