{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Handout20 - Lecture 20 1 Working with multiple observations...

This preview shows pages 1–6. Sign up to view the full content.

Lecture 20 1. Working with multiple observations: long form and wide form 2. Proc SQL 3. Counting observations with SQL and Transpose 4. Proc SQL to combine datasets: fuzzy merge 5. Longitudinal data: response feature analysis 6. Area under the curve (AUC) 1 Long form : multiple observations per subject, one measurement ( income ) in each observation, with variables identifying subject ID and observation number ( year ) family_ Obs id income year 1 1 66483 1990 2 1 69146 1991 3 1 74643 1992 Wide form : one observation per subject, all measurements ( income ) in one observation, with variables identifying subject ID, and observation number ( year ) encoded in variable name family_ income_ income_ income_ income_ income_ income_ Obs id 1990 1991 1992 1993 1994 1995 1 1 66483 69146 74643 79783 81710 86143 2 2 17510 . 19484 20979 21268 22998 2

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Long form . Required for graphing and analysis procedures Wide form . All measurements from a subject are available for computation because they are all in the same row. SAS Data step works with one observation (row) at a time. 3 ways to access the values in a column from more than one observation: • using RETAIN statement to store values “across” rows Proc Transpose pivots data to put multiple values in the same row (= wide form) Proc SQL ( S tructured Q uery L anguage) 3 Transpose Help chapter: SAS Help > SAS Products > Base SAS > Base SAS 9.2 Procedures Guide > Procedures > Proc Transpose SQL Help chapter: SAS Help > SAS Products > Base SAS > SAS 9.2 SQL Procedure User’s Guide 4
Proc SQL applied to one dataset Family economic data, in long form. 3 to 6 annual observations per family. family_ Obs id income year expenses debt cohort 1 1 66483 1990 49804 no A 2 1 69146 1991 65634 no A 3 1 74643 1992 61820 no A 1993 missing 4 1 81710 1994 85504 yes A 5 1 86143 1995 75640 no A 6 2 17510 1990 21609 yes B 7 2 17947 1991 12085 no B 1992 missing 8 2 20979 1993 22985 yes B 9 2 21268 1994 11097 no B 10 2 22998 1995 21768 no B Count number of observations per family. 5 Proc SQL; create table pubh.M as select family_id, count(income) as n_years_income from family_economic_data group by family_id; quit; Create SAS permanent dataset pubh.M by selecting these variables from family_economic_data : group observations for each distinct family_ID , create n_years_income = COUNT(income) make one observation per family_ID with 2 variables: family_ID, n_years_income Ends with quit , not run . 6

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
family_ n_years_ Obs id income 1 1 5 2 2 5 3 3 6 4 4 6 5 5 5 Summary: pattern of missing observations from Proc Cumulative Cumulative n_years_income Frequency Percent Frequency Percent 3 2 4.00 2 4.00 4 2 4.00 4 8.00 5 17 34.00 21 42.00 6 29 58.00 50 100.00 7 Select variables that do not repeat within family_id groups: Proc SQL; create table M2 as select * , * = all variables count(income) as n_years_income no comma after last variable selected from family_economic_data group by family_id; quit; Summary count is merged back: family_ n_years_ Obs id income year expenses debt cohort income 1 1 66483 1990 49804 no A 5 2 1 81710 1994 85504 yes A 5 3 1 74643 1992 61820 no A 5 4 1 86143 1995 75640 no A 5 5 1 69146 1991 65634 no A 5 8
Another way to count nonmissing observations Use Proc Transpose to reshape from long to wide form: Proc Transpose data=long out=wide prefix =income_ ; ID year; VAR income; BY family_id; family_ income_ income_ income_

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 19

Handout20 - Lecture 20 1 Working with multiple observations...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online