SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.

Slides:



Advertisements
Similar presentations
The INFILE Statement Reading files into SAS from an outside source: A Very Useful Tool!
Advertisements

Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
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.
I OWA S TATE U NIVERSITY Department of Animal Science Getting Started Using SAS Software Animal Science 500 Lecture No. 2.
Public Health 5415 Biostatistical Methods II Spring 2005 Greg Grandits Class Times Monday10:10am-12:05pm Wednesday10:10am-11:00am.
Today: Run SAS programs on Saturn (UNIX tutorial) Runs SAS programs on the PC.
Biostatistical Methods II PubH 6415 Spring PubH 6415 – Biostatistics I Instructor: Susan Telke (office hours: lecture.
Categorical Data Analysis using SAS. 2 List the components of a SAS program. Open an existing SAS program and run it. Discuss the Chi Square Test of Independence.
SAS ® Regression Essentials. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
NonParametric Statistics using SAS. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
Welcome to the Exciting World of ! Lessons to familiarize yourself with.
1 SAS SAS is a statistics software package developed by SAS Institute Inc. in U.S.A. SAS products include SAS/STAT, SAS/IML, SAS/OR, etc. The most.
SPSS 1: An Introduction to the Statistical Package SPSS Suzie Cro MRC Clinical Trials Unit.
EPLS Lab Software Orientation SAS. Orientation Overview Background Getting Started SAS Windows.
SAS Workshop INTRODUCTORY ASPECTS SPRING 2012 January 20121K. F. O'Brien.
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.
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
SAS ® ANOVA Essentials. 2 List the components of a SAS program. Open an existing SAS program and run it. Objectives.
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.
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS ESSENTIALS -- Elliott & Woodward1.
Introduction to SAS BIO 226 – Spring Outline Windows and common rules Getting the data –The PRINT and CONTENT Procedures Manipulating the data.
1 Experimental Statistics - week 4 Chapter 8: 1-factor ANOVA models Using SAS.
Introduction to SAS. What is SAS? SAS originally stood for “Statistical Analysis System”. SAS is a computer software system that provides all the tools.
1 Experimental Statistics - week 2 Review: 2-sample t-tests paired t-tests Thursday: Meet in 15 Clements!! Bring Cody and Smith book.
Lesson 5 - Topics Formatting Output Working with Dates Reading: LSB:3:8-9; 4:1,5-7; 5:1-4.
Quantify the Example Data First, code and quantify the data (assign column locations & variable names) Use the sample data to create a data set from the.
Math 3400 Computer Applications of Statistics Lecture 1 Introduction and SAS Overview.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS 介绍和举例 Presented by 经济实验教学中心 商务数据挖掘中心. Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using.
BMTRY 789 Introduction to SAS Programming Lecturer: Annie N. Simpson, MSc.
Knowing Understanding the Basics Writing your own code SAS Lab.
Chapter 1: Introduction to SAS  SAS programs: A sequence of statements in a particular order  Rules for SAS statements: –Every SAS statement ends in.
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.
SAS: The last of the great mainframe stats packages STA431 Winter/Spring 2013.
1 EPIB 698E Lecture 1 Notes Instructor: Raul Cruz 7/9/13.
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.
Lecture 3 Topic - Descriptive Procedures Programs 3-4 LSB 4:1-4.4; 4:9:4:11; 8:1-8:5; 5:1-5.2.
1 Introduction to SAS Available at
Introduction to SAS Essentials Mastering SAS for Data Analytics Alan Elliott and Wayne Woodward SAS Essentials - Elliott & Woodward1.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
Lecture 4 Ways to get data into SAS Some practice programming
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.
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
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 16 & 17 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapters 3 & 4 By Tasha Chapman, Oregon Health Authority.
PubH 6420 Introduction to SAS Programming
SAS Programming Training
SAS Programming Training
SAS Programming Introduction to SAS.
Chapter 1: Introduction to SAS
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.
SAS Programming Training
Instructor: Raul Cruz 9/4/13
Introduction to SAS Lecturer: Chu Bin Lin.
Introduction to SAS Essentials Mastering SAS for Data Analytics
Presentation transcript:

SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5 th Edition Course packet of slides and other info (provided)

Course Information Access to SAS via PCs (Version 9.4) 6 lectures and 6 class exercises Emphasis on reading and processing data Goal: Gain experience in SAS for TA and RA work and general use as Biostatistician

SAS Usage Used extensively at academic and business environments (medical device and pharmaceutical companies) Many analyses of publications in medical journals use SAS SAS invests extensive resources to R & D.

Lecture 1 Introduction to SAS Readings: LSB (Chapter 1) Cody & Smith (Chapter 1)

SAS OS/Environment Windows PC UNIX Others

What is SAS ? SAS is a programming language that reads, processes, and performs statistical analyses of data. A SAS program is made up of programming statements which SAS interprets to do the above functions. Note: Programming statements are sometimes referred to as “syntax” or programming “code”. A program is sometimes called a “syntax” file.

Parts of SAS Program DATA step –Reads in and processes your raw data and makes a SAS dataset. Procedures (PROCS) –Performs specific statistical analyses –Some procedures are utility procedures such as PROC SORT that is used to sort your data

Raw Data Read in Data Process Data (Create new variables) Output Data (Create SAS Dataset) Analyze Data Using Statistical Procedures Data Step PROCs

Raw Data Sources You type data into the program Text file (.csv or.txt) Spreadsheet like Excel Database like Oracle or Access SAS dataset

Structure of Data Made up of rows and columns Rows in SAS are called observations Columns in SAS are called variables Together they make up the dataset An observation is all the information for one entity (patient, patient visit, clinical center, county) SAS processes data one observation at a time

Types of Variables In SAS Numeric (e.g. age, blood pressure) –54, 140 Character (patient ID, diagnosis) –A001, TIA, 0410

Rules for SAS Statements SAS statements end with a semicolon (;) DATA demo; INFILE DATALINES; INPUT gender $ age; SAS statements can be entered in lower or uppercase data demo; infile datalines; input gender $ age; DATA DEMO; INFILE DATALINES; INPUT GENDER $ AGE; IS SAME AS :

Rules for SAS Statements Multiple SAS statements can appear on one line DATA demo; INFILE DATALINES; INPUT gender $ age; X1 = 0; X2 = 0; X3 = 0; X4 = 0; A SAS statement can use multiple lines INPUT gender $ age marstat;

Rules for SAS Variables Variable names can be from 1-32 characters and must begin with A-Z or an underscore (_). No special characters except underscore is allowed. OK AS VARIABLE NAMES dbp12 DiastolicBloodPressure diastolic_BP Not OK AS VARIABLE NAMES 12dbp dbp 12 dbp*12

* This is a short example program to demonstrate what a SAS program looks like. This is a comment statement because it begins with a * and ends with a semi-colon ; DATA demo; INFILE DATALINES; INPUT gender $ age marstat $ credits state $ ; if credits > 12 then fulltime = 'Y'; else fulltime = 'N'; if state = 'MN' then resid = 'Y'; else resid = 'N'; DATALINES; F 23 S 15 MN F 21 S 15 WI F 22 S 09 MN F 35 M 02 MN F 22 M 13 MN F 25 S 13 WI M 20 S 13 MN M 26 M 15 WI M 27 S 05 MN M 23 S 14 IA M 21 S 14 MN M 29 M 15 MN ; RUN; PROC PRINT DATA=demo ; VAR gender age marstat credits fulltime state ; RUN; DATA STEP SAS PROCEDURE

1 DATA demo; Create a SAS dataset called demo 2 INFILE DATALINES; Where is the data? 3 INPUT gender $ What are the variable age names and types? marstat $ credits state $ ; 4 if credits > 12 then fulltime = 'Y'; else fulltime = 'N'; 5 if state = 'MN' then resid = 'Y'; else resid = 'N'; Statements 4 and 5 create 2 new variables New variable definitions go here

6 DATALINES; Tells SAS the data is coming F 23 S 15 MN F 21 S 15 WI F 22 S 09 MN F 35 M 02 MN F 22 M 13 MN F 25 S 13 WI M 20 S 13 MN M 26 M 15 WI M 27 S 05 MN M 23 S 14 IA M 21 S 14 MN M 29 M 15 MN ; Tells SAS the data is ending 7 RUN; Tells SAS to run the statements above

Syntax for Procedures PROC PROCNAME DATA=datasetname ; substatements/ ; The WHERE statement is a useful substatement available to all procedures. PROC PRINT DATA=demo ; VAR marstat ; WHERE state = 'MN';

Some common procedures PROC PRINT print out your data - always a good idea!! PROC CONTENTS Displays dataset information including variable names PROC MEANS descriptive statistics for continuous data PROC FREQ descriptive statistics for categorical data PROC UNIVARIATE very detailed descriptive statistics for continuous data PROC TTEST performs t-tests (continuous data)

SAS Environment Main SAS Windows (PC) Editor Window – where you type your program Log Window –lists program statements processed, giving notes, warnings and errors. Always look at the log window ! Tells how SAS understood your program Output Window/Results Viewer – gives the output generated from the PROCs Results Window – index to all of your output Submit program by clicking on run icon

SAS Windows

* This is a short example program to demonstrate what a SAS program looks like. This is a comment statement because it begins with a * and ends with a semi-colon ; DATA demo; INFILE DATALINES; INPUT gender $ age marstat $ credits state $ ; if credits > 12 then fulltime = 'Y'; else fulltime = 'N'; if state = 'MN' then resid = 'Y'; else resid = 'N'; DATALINES; F 23 S 15 MN F 21 S 15 WI F 22 S 09 MN F 35 M 02 MN F 22 M 13 MN F 25 S 13 WI M 20 S 13 MN M 26 M 15 WI M 27 S 05 MN M 23 S 14 IA M 21 S 14 MN M 29 M 15 MN ; RUN; TITLE 'Running the Example Program'; PROC PRINT DATA=demo ; VAR gender age marstat credits fulltime state ; RUN;

Messages in SAS Log Errors – fatal in that program will abort Warnings – messages that are usually important Notes – messages that may or may not be important (notes and warnings will not abort your program)

LOG WINDOW (or file) NOTE: Copyright (c) by SAS Institute Inc., Cary, NC, USA. NOTE: SAS (r) Proprietary Software Release 9.3 (TS1M1) Licensed to UNIVERSITY OF MINNESOTA, Site NOTE: This session is executing on the WINDOWS 7 platform. NOTE: SAS initialization used: real time 7.51 seconds cpu time 0.89 seconds 1 * This is a short example program to demonstrate what a 2 SAS program looks like. This is a comment statement because 3 it begins with a * and ends with a semi-colon ; 4 5 DATA demo; 6 INFILE DATALINES; 7 INPUT gender $ age marstat $ credits state $ ; 8 9 if credits > 12 then fulltime = 'Y'; else fulltime = 'N'; 10 if state = 'MN' then resid = 'Y'; else resid = 'N'; 11 DATALINES; NOTE: The data set WORK.DEMO has 12 observations and 7 variables. NOTE: DATA statement used: real time 0.38 seconds cpu time 0.06 seconds

25 RUN; 26 TITLE 'Running the Example Program'; 27 PROC PRINT DATA=demo ; 28 VAR gender age marstat credits fulltime state ; 29 RUN; NOTE: There were 12 observations read from the data set WORK.DEMO. NOTE: PROCEDURE PRINT used: real time 0.19 seconds cpu time 0.02 seconds 30 PROC MEANS DATA=demo N SUM MEAN; 31 VAR age credits ; 32 RUN; NOTE: There were 12 observations read from the data set WORK.DEMO. NOTE: PROCEDURE MEANS used: real time 0.25 seconds cpu time 0.03 seconds 33 PROC FREQ DATA=demo; TABLES gender; 34 RUN; NOTE: There were 12 observations read from the data set WORK.DEMO. NOTE: PROCEDURE FREQ used: real time 0.15 seconds cpu time 0.03 seconds

OUTPUT WINDOW Running the Example Program Obs gender age marstat credits fulltime state 1 F 23 S 15 Y MN 2 F 21 S 15 Y WI 3 F 22 S 9 N MN 4 F 35 M 2 N MN 5 F 22 M 13 Y MN 6 F 25 S 13 Y WI 7 M 20 S 13 Y MN 8 M 26 M 15 Y WI 9 M 27 S 5 N MN 10 M 23 S 14 Y IA 11 M 21 S 14 Y MN 12 M 29 M 15 Y MN The MEANS Procedure Variable N Sum Mean age credits The FREQ Procedure Cumulative Cumulative gender Frequency Percent Frequency Percent F M SAS 9.3 will display html output by default into the results viewer.

Exercise 1 Let's Write Our First Program! Click on SAS icon