Presentation is loading. Please wait.

Presentation is loading. Please wait.

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!

Similar presentations


Presentation on theme: "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!"— Presentation transcript:

1 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!

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

3 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. 80-81 (2 nd Ed) pp. 90-91 (3 rd Ed) For example, the TODAY function returns a SAS date value equal to today’s date Age = ((TODAY() – DOB) / 365.25); Use a date as a constant EarthDay05 = ’22APR2005’D;

4 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) / 365.25); (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)

5 Summer 2009BMTRY 789 Introduction to SAS Programming5 Data librarycards; INFILE ‘c:MyData\Dates.dat’ TRUNCOVER; INPUT Name$ :11. +1 BirthDate: Date9. +1 IssueDate :MMDDYY10.; ExpireDate = IssueDate + (365.25 *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;

6 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.)

7 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.

8 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)

9 Summer 2009BMTRY 789 Introduction to SAS Programming9 Example (SAS example to be run class) Data Patients; Input PTID VisDate CD4Cell; Format VisDate MMDDYY8.; Cards; 001 01/02/85 125 001 07/25/85 210 001 09/03/84 220 002 12/12/92 180 002 10/19/90 223 002 06/14/91 190 003 07/23/92 150 003 06/01/93 125 ; 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;

10 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.

11 Summer 2009BMTRY 789 Introduction to SAS Programming11 Example (SAS example to be run class) Data Patients; Input PTID VisDate CD4Cell; Format VisDate MMDDYY8.; Cards; 001 01/02/85 125 001 07/25/85 210 001 09/03/84 220 002 12/12/92 180 002 10/19/90 223 002 06/14/91 190 003 07/23/92 150 003 06/01/93 125 ; 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;

12 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 12 17 19 TREAT 23 25 29 CONTROL 19 18 16 TREAT 22 22 29 ; 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;

13 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 12 17 19 TREAT 23 25 29 CONTROL 19 18 16 TREAT 22 22 29 ; 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;


Download ppt "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!"

Similar presentations


Ads by Google