SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.

Slides:



Advertisements
Similar presentations
The SAS ® System Additional Information on Statistical Analysis Programming.
Advertisements

The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Introduction to SAS Programming Christina L. Ughrin Statistical Software Consulting Some notes pulled from SAS Programming I: Essentials Training.
Statistics in Science  Introducing SAS ® software Acknowlegements to David Williams Caroline Brophy.
SAS BASICS Technology Short Courses: Fall 2009 Kentaka Aruga.
Understanding SAS Data Step Processing Alan C. Elliott stattutorials.com.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Into to SAS ®. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Creating SAS® Data Sets
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
Chapter 9 Producing Descriptive Statistics PROC MEANS; Summarize descriptive statistics for continuous numeric variables. PROC FREQ; Summarize frequency.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
Chapter 20 Creating Multiple Observations from a Single Record Objectives Create multiple observations from a single record containing repeating blocks.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
SAS Efficiency Techniques and Methods By Kelley Weston Sr. Statistical Programmer Quintiles.
EPIB 698C Lecture 2 Notes Instructor: Raul Cruz 2/14/11 1.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
BMTRY 789 Lecture 2 SAS Syntax, entering raw data, etc. Lecturer: Annie N. Simpson, MSc. Readings – Chapters 1, 2, 12, & 13 Lab Problems 1.1, 1.2, 1.3,
I OWA S TATE U NIVERSITY Department of Animal Science Getting Your Data Into SAS (Chapter 2 in the Little SAS Book) Animal Science 500 Lecture No. 3 September.
Lesson 2 Topic - Reading in data Chapter 2 (Little SAS Book)
Introduction to SAS Essentials Mastering SAS for Data Analytics
ISU Basic SAS commands Laboratory No. 1 Computer Techniques for Biological Research Animal Science 500 Ken Stalder, Professor Department of Animal Science.
Summer SAS Workshop Lecture 2. Summer Summer SAS Workshop Lecture 2 I’ve got Data…how do I get started? Libname Review How do you do arithmetic.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
How to start using SAS Tina Tian. The topics An overview of the SAS system Reading raw data/ create SAS data set Combining SAS data sets & Match merging.
Here’s another problem (see section 2.13 on page 54). A file contains two different types of records (say A’s and B’s) and we only want to read in the.
SAS Basics. Windows Program Editor Write/edit all your statements here. Log Watch this for any errors in program as it runs. Output Will automatically.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
1 Statistical Software Programming. STAT 6360 –Statistical Software Programming Data Input in SAS Many ways to get your data into SAS: –Through data entry.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
Computing with SAS Software A SAS program consists of SAS statements. 1. The DATA step consists of SAS statements that define your data and create a SAS.
FORMAT statements can be used to change the look of your output –if FORMAT is in the DATA step, then the formats are permanent and stored with the dataset.
Chapter 2 Getting Data into SAS Directly enter data into SAS data sets –use the ViewTable window. You can define columns (variables) with the Column Attributes.
1 Introduction to SAS Available at
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
1 EPIB 698C Lecture 1 Instructor: Raul Cruz-Cano
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
The Urban Institute - SAS Training6/9/20161 SAS Training This SAS Training Course was designed to introduce users at The Urban Institute to SAS programming.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 14 & 19 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 16 & 17 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 5 & 6 By Ravi Mandal.
Session 1 Retrieving Data From a Single Table
Temporary vs. Permanent SAS Data Sets
Applied Business Forecasting and Regression Analysis
SAS Programming Training
Lesson 2 Topic - Reading raw data into SAS
SAS Programming Training
Instructor: Raul Cruz-Cano 7/9/2012
Chapter 2: Getting Data into SAS
SAS Programming Introduction to SAS.
SAS Programming I Matthew A. Lanham Doctoral Student
Chapter 1: Introduction to SAS
Instructor: Raul Cruz-Cano
Lesson 8 - Topics Creating SAS datasets from procedures
Tamara Arenovich Tony Panzarella
Chapter 4: Sorting, Printing, Summarizing
Introduction to SAS A SAS program is a list of SAS statements executed in order Every SAS statement ends with a semicolon! SAS statements can be in caps.
Working With Dates: Dates Come in Many Ways
SAS Programming Training
Working With Dates: Dates Come in Many Ways
Producing Descriptive Statistics
Instructor: Raul Cruz 9/4/13
Introduction to SAS Essentials Mastering SAS for Data Analytics
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority

Topics covered…  SAS libraries  Reading data from external files  txt and csv  Filename statement  Datalines  SET statement  Basic PROC Print  Basic PROC Contents  Basic PROC Freq  Basic PROC Means

SAS libraries

 LIBNAME statement assigns a libref  Libref (short for “Library Reference”) is an alias or nickname for a directory or folder for SAS datasets

SAS Datasets: Permanent location of all SAS Datasets SAS Datasets: Permanent location of all SAS Datasets Text and CSV: Text and CSV data files used to create the SAS Datasets Text and CSV: Text and CSV data files used to create the SAS Datasets Would assign libref using LIBNAME statement

LIBNAME statement: Assigns a libref Libref is an alias for a directory or folder where you store permanent SAS datasets Libref can be anything you choose Libref only exists for current SAS session LIBNAME statement: Assigns a libref Libref is an alias for a directory or folder where you store permanent SAS datasets Libref can be anything you choose Libref only exists for current SAS session SAS libraries

 LIBNAME statement assigns a libref  Libref (short for “Library Reference”) is an alias or nickname for a directory or folder for SAS datasets  Dataset references contain two parts:  libref  dataset-name  Looks like: libref.dataset-name  If libref is blank, the default is the Work library

Dataset reference: Consists of two parts – Libref.dataset-name mozart.test_scores is short for c:\books\learning\test_scores Default is Work Dataset reference: Consists of two parts – Libref.dataset-name mozart.test_scores is short for c:\books\learning\test_scores Default is Work SAS libraries

SAS work library  Work is a temporary library  SAS datasets created in Work only exist during SAS session  Once SAS session ends, datasets are erased  Do not need to assign a libref for Work or specify it in dataset references data Test_Scores; is the same as data work.Test_Scores;

LIBNAME statement: Assigns a libref Use the libref for saving data and for retrieving data LIBNAME statement: Assigns a libref Use the libref for saving data and for retrieving data SAS libraries

Explorer Window: See libraries and SAS datasets Explorer Window: See libraries and SAS datasets

Active Libraries: Double click on a library to see the datasets in it Active Libraries: Double click on a library to see the datasets in it

LIBNAME examples Oops! Your password is showing! Oops! Your password is showing!

LIBNAME trick  Save your commonly used and/or passworded LIBNAME statements in a text file (using Notepad)  Use a %include statement to reference the text file at the beginning of every SAS program SAS will include the code in the text file as if it were part of your program.

Reading external data

Four variables: Gender, Age, Height (in inches), Weight (in pounds) Variables separated by blanks Four variables: Gender, Age, Height (in inches), Weight (in pounds) Variables separated by blanks Reading data from a text file

INFILE – where to find the data INPUT – variable names to associate with each data value ($ indicates character variable. Otherwise numeric.) INFILE – where to find the data INPUT – variable names to associate with each data value ($ indicates character variable. Otherwise numeric.) Reading data from a text file

Results of PROC Print of “Demographics” Obs – short for “observation” (part of PROC Print output) Numbers observations from 1 to N Results of PROC Print of “Demographics” Obs – short for “observation” (part of PROC Print output) Numbers observations from 1 to N Reading data from a text file

Four variables: Gender, Age, Height (in inches), Weight (in pounds) Variables separated by commas Four variables: Gender, Age, Height (in inches), Weight (in pounds) Variables separated by commas Reading data from a csv file

dsd option (delimiter-sensitive data):  Changes default delimiter from blank to comma  If two delimiters in a row, assumes missing value between  Quotes stripped from character values dsd option (delimiter-sensitive data):  Changes default delimiter from blank to comma  If two delimiters in a row, assumes missing value between  Quotes stripped from character values Reading data from a csv file

Results of PROC Print of “Demographics” SAS data results are the same Results of PROC Print of “Demographics” SAS data results are the same Reading data from a csv file

Other delimiters  Use the dlm= (or delimiter= ) option to specify data delimiters other than blanks or commas  Example: infile 'D:\Data\mydata.txt' dlm=':';  Can use dsd and dlm= options together  Performs all functions of dsd, but overrides default delimiter

Filename  FILENAME statement assigns a fileref  Fileref (short for “File Reference”) is an alias or nickname for an external file

Filename  Useful when you need to read two or more files with same format (such as quarterly data)

Datalines  Allows dataset to be created within SAS program  Can be useful for creating a quick set of test data  Use either datalines or cards options  Follow with semi-colon after last line of data

SET statement

 After you’ve brought your data into a SAS dataset, most of your DATA steps will look like this: SET statement Creates a new dataset called “Females” Uses previous dataset “AllData” as the basis of the new dataset Applies these modifications to the new dataset

SET statement  The SET statement is similar to an INPUT statement  Except instead of a raw data file, you are reading observations from a SAS dataset  Can read in temporary or permanent SAS datasets

PROC Print

 PROC Print can be used to list the data in a SAS dataset

Results of PROC Print of “Demographics” PROC Print

 Many options to control output of PROC Print  noobs – Suppresses “OBS” column in output  (obs=2) – Only prints the first two observations Can put in any number: 1 through N Must be placed in parentheses after data= option  var statement – Only prints listed variables

We’ll discuss other PROC Print options in later chapters PROC Print

PROC Contents

 PROC Contents can be used to display the metadata (descriptor portion) of the SAS dataset

PROC Contents Results of PROC Contents of “Demographics”

PROC Contents Number of observations and variables Variable list Dataset name File name

PROC Contents variable list  # - Variable number (varnum)  Variable – Name of variable  Type – Numeric or Character  Len – Variable length  Format – How the data is displayed  Informat – How the data was read by SAS

 Variables listed in alphabetical order by default  Uppercase alphabetized before lowercase (e.g., “ZZTOP” would be alphabetized before “aerosmith”)  Use the varnum option to list variables in order they were created in PROC Contents variable list

PROC Freq

 PROC Freq can be used to run simple frequency tables on your data

PROC Freq Results of PROC Freq of “Demographics”

 Use the table statement to only print selected variables  Use the nocum option to suppress cumulative statistics  Use the nopercent option to suppress percent statistics  Can use options together or separately PROC Freq

 Can create simple cross-tabulations

PROC Freq  Use the list option to display cross-tab tables in a list format

PROC Means

 PROC Means can be used to run simple summary statistics on your data

Results of PROC Means of “Demographics” PROC Means

 Many options to control output of PROC Means  NMiss Mean Median – Examples of statistics that can be specified in PROC Means (see later slide for list of statistical keywords)  class statement – Allows for grouping by categorical variables  var statement – Only provides statistics for listed analysis variables

We’ll discuss other PROC Freq and PROC Means options in later chapters PROC Means

Examples of statistics that can be run with PROC Means

Read chapters 5 & 6 and sections 3.9 through 3.14 For next week…