BMTRY 789 Lecture 3: Categorical Data and Dates Readings – Chapter 3 & 4 Lab Problems 3.1, 3.2, 3.19, 4.1, 4.3, 4.5 Homework – HW 2 Book Problems Due 6/24!

Slides:



Advertisements
Similar presentations
Statistical Methods Lynne Stokes Department of Statistical Science Lecture 7: Introduction to SAS Programming Language.
Advertisements

SAS Programming:File Merging and Manipulation. Reading External Files (review) data barf; * create the dataset BARF; infile ’s:\mysas\Table7.1'; * open.
Introduction to SAS Programming Christina L. Ughrin Statistical Software Consulting Some notes pulled from SAS Programming I: Essentials Training.
I OWA S TATE U NIVERSITY Department of Animal Science Modifying and Combing SAS Data Sets (Chapter in the 6 Little SAS Book) Animal Science 500 Lecture.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
1 Computer Applications in Epidemiology Dongmei Li Lecture 26 5/6/2009.
PROC_CODEBOOK: An Automated, General Purpose Codebook Generator
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
Data Cleaning 101 Ron Cody, Ed.D Robert Wood Johnson Medical School Piscataway, NJ.
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Lecture 5 Sorting, Printing, and Summarizing Your Data.
SAS Workshop Lecture 1 Lecturer: Annie N. Simpson, MSc.
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.
SAS Macro: Some Tips for Debugging Stat St. Paul’s Hospital April 2, 2007.
SAS ® PROC SQL or Vanilla Flavor Cecilia Mauldin January
BMTRY 789 Introduction to SAS Programming Lecturer: Annie N. Simpson, MSc.
Use the UPDATE statement to: –update a master dataset with new transactions (e.g. a bank account updated regularly with deposits and withdrawals…). Not.
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)
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
Chapter 3 “Working With Your Data” concerns programming in the DATA step - putting lines of SAS code between a DATA and PROC statement… Creating new variables.
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.
Lesson 6 - Topics Reading SAS datasets Subsetting SAS datasets Merging SAS datasets.
Chapter 22: Using Best Practices 1 STAT 541 ©Spring 2012 Imelda Go, John Grego, Jennifer Lasecki and the University of South Carolina.
Chapter 5 Reading and Manipulating SAS ® Data Sets and Creating Detailed Reports Xiaogang Su Department of Statistics University of Central Florida.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
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.
Chapter 4 concerns various SAS procedures (PROCs). Every PROC operates on: –the most recently created dataset –all the observations –all the appropriate.
Chapter 1: Overview of SAS System Basic Concepts of SAS System.
Summer SAS Workshop Lecture 3. Summer SAS Workshop Website
Time Series Data Processes by Tai Yu April 15, 2013.
SAS for Data Management and Analysis
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.
“LAG with a WHERE” and other DATA Step Stories Neil Howard A.
BMTRY 789 Lecture 6: Proc Sort, Random Number Generators, and Do Loops Readings – Chapters 5 & 6 Lab Problem - Brain Teaser Homework Due – HW 2 Homework.
Beginning C For Engineers Fall 2005 Lecture 3: While loops, For loops, Nested loops, and Multiple Selection Section 2 – 9/14/05 Section 4 – 9/15/05 Bettina.
Use the SET statement to: –create an exact copy of a SAS dataset –modify an existing SAS dataset by creating new variables, subsetting (using a subsetting.
Lesson 2 Topic - Reading in data Programs 1 and 2 in course notes –Chapter 2 (Little SAS Book)
BMTRY 789 Lecture9: Proc Tabulate Readings – Chapter 11 & Selected SUGI Reading Lab Problems , 11.2 Homework Due Next Week– HW6.
Chapter 6: Modifying and Combining Data Sets  The SET statement is a powerful statement in the DATA step DATA newdatasetname; SET olddatasetname;.. run;
SAS Programming Training Instructor:Greg Grandits TA: Textbooks:The Little SAS Book, 5th Edition Applied Statistics and the SAS Programming Language, 5.
1 Checking Data with the PRINT and FREQ Procedures.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 26 By Tasha Chapman, Oregon Health Authority.
SAS ® 101 Based on Learning SAS by Example: A Programmer’s Guide Chapter 25 By Tasha Chapman, Oregon Health Authority.
Copyright 2009 The Little Engine That Could: Using EXCEL LIBNAME Engine Options to Enhance Data Transfers between SAS® and Microsoft® Excel Files William.
Longitudinal Data Techniques: Looking Across Observations Ronald Cody, Ed.D., Robert Wood Johnson Medical School.
Chapter 6: Modifying and Combining Data Sets
Chapter 2: Getting Data into SAS
Instructor: Raul Cruz-Cano
Lesson 7 - Topics Reading SAS data sets
Working With Dates: Dates Come in Many Ways
Working With Dates: Dates Come in Many Ways
CS148 Introduction to Programming II
File Sharing and Processing Grouped Data
Hans Baumgartner Penn State University
Presentation transcript:

BMTRY 789 Lecture 3: Categorical Data and Dates Readings – Chapter 3 & 4 Lab Problems 3.1, 3.2, 3.19, 4.1, 4.3, 4.5 Homework – HW 2 Book Problems Due 6/24!

Summer 2009BMTRY 789 Introduction to SAS Programming2 Think about what you want … consider if it is the best method to go about it

Summer 2009BMTRY 789 Introduction to SAS Programming3 Date Functions & Expressions SAS date functions perform a number of handy operations (“The Little SAS Book” Readings pp (2 nd Ed) pp (3 rd Ed) For example, the TODAY function returns a SAS date value equal to today’s date Age = ((TODAY() – DOB) / ); Use a date as a constant EarthDay05 = ’22APR2005’D;

Summer 2009BMTRY 789 Introduction to SAS Programming4 Why are SAS dates done this way? SAS can use the SAS date to calculate many important things, just as it would any other numeric variable. AGE = INT ((ADMIT – DOB) / ); (Calculates patient age at admission) Or AGE = INT (YRDIF(ADMIT, DOB, ‘Actual’)); LEN_STAY = DISCHRG – ADMIT +1; (Calculates the length of stay including the admission day and the discharge day)

Summer 2009BMTRY 789 Introduction to SAS Programming5 Data librarycards; INFILE ‘c:MyData\Dates.dat’ TRUNCOVER; INPUT Name$ : BirthDate: Date9. +1 IssueDate :MMDDYY10.; ExpireDate = IssueDate + ( *3); ExpireQuarter = QTR(ExpireDate); If IssueDate > ’01jan1999’D Then NewCard = ‘yes’; Run; Proc Print Data = librarycards; FORMAT IssueDate MMDDYY8. ExpireDate WEEKDATE17.; Title ‘SAS Dates without and with Formats’; Run;

Summer 2009BMTRY 789 Introduction to SAS Programming6 Longitudinal Data Longitudinal data are collected on a group of subjects over time. (Also known as Repeated Measures or Vertical File, etc.)

Summer 2009BMTRY 789 Introduction to SAS Programming7 The SET statement ‘SET’ reads observations from a SAS data set to a new SAS data set. It brings a SAS data set, one observation at a time, into the DATA step for processing. Syntax: Example: DATA new-data-set; DATA Friday; SET old-data-set;SET sales; Run;If Day = ‘f’; *subsetting If; Total = Popcorn + Soda; Run; *You can use the same name for the ‘old’ and ‘new’ data sets if you want to overwrite the old with the new manipulation.

Summer 2009BMTRY 789 Introduction to SAS Programming8 FIRST.byvar & LAST.byvar Automatic variable available only in special circumstances. MUST SORT the data by the byvariable first! The FIRST.variable and LAST.variable are available when you are using a BY statement in a DATA step. The FIRST.variable will have a value of 1 when SAS is processing an observation with the first occurrence of a new value for that variable and a value of 0 for the other observations. Similarly, if the LAST.variable is the last occurrence of the value it will equal 1 and 0 if it is not the last value. (logical variables)

Summer 2009BMTRY 789 Introduction to SAS Programming9 Example (SAS example to be run class) Data Patients; Input PTID VisDate CD4Cell; Format VisDate MMDDYY8.; Cards; /02/ /25/ /03/ /12/ /19/ /14/ /23/ /01/ ; Run; Proc Print Data = Patients; Title “Print out of Patients Data”; Run; Proc Sort Data = Patients; By PTID VisDate; Run; Data LastVisit; Set Patients; By PTID; If LAST.PTID; Run; Proc Print data = LastVisit; Title “Print out of LastVisit Data”; Run;

Summer 2009BMTRY 789 Introduction to SAS Programming10 LAG Function What do you do if you want to compute the change between a single variable from visit to visit with your data in a longitudinal structure? LAG Function = The value of the variable, the last time the LAG function executed (i.e. the previous value). Lets look at our last example but assume that we want to look at the differences between our CD4 cell counts from the baseline (first visit) to the final visit.

Summer 2009BMTRY 789 Introduction to SAS Programming11 Example (SAS example to be run class) Data Patients; Input PTID VisDate CD4Cell; Format VisDate MMDDYY8.; Cards; /02/ /25/ /03/ /12/ /19/ /14/ /23/ /01/ ; Run; Proc Sort Data = Patients; By PTID VisDate; Run; Data FirstLastCD4; Set Patients; By PTID; If First.PTID or LAST.PTID; DiffCD4= CD4Cell – Lag (CD4Cell); Run; Proc Print data = FirstLastCD4; Title ‘Print out of FirstLastCD4 Data’; Run;

Summer 2009BMTRY 789 Introduction to SAS Programming12 The Basics of Proc Format (Temporary) Libname Felix ‘C:\SASDATA’; Proc Format; Value $groupFMT “TREAT”=“Treatment Group” “CONTROL”=“Control Group”; Run; Data Felix.Ex4a Input Group$ X Y Z; Format Group $groupFMT.; Datalines; CONTROL TREAT CONTROL TREAT ; Program to read a permanent SAS Data Set with Formats: Libname C ‘C:\SASDATA’; Proc Format; Value $groupFMT ‘TREAT’=‘Treatment Grp’ ‘CONTROL’=‘Control Grp’; Run; Proc Print Data=C.Ex4a; Format group $groupFMT; Run;

Summer 2009BMTRY 789 Introduction to SAS Programming13 The Basics of Proc Format (Permanent) Libname Felix ‘C:\SASDATA’; Options FMTSEARCH = (Felix); ***We will place the permanent SAS data sets and the formats in C:\SASDATA; Proc Format Library=Felix; Value $groupFMT ‘TREAT’=‘Treatment Grp’ ‘CONTROL’=‘Control Grp’; Run; Data Felix.Ex4a Input Group$ X Y Z; Format Group $groupFMT.; Datalines; CONTROL TREAT CONTROL TREAT ; Program to read a permanent SAS Data Set with Formats: Libname C ‘C:\SASDATA’; Options FMTSEARCH= ( C ); ***Tell the program to look in C:\SASDATA for user defined formats; Proc Print Data=C.Ex4a; Run;