Chapter 8. Rearranging data

Chapter 8. Rearranging data - 1 Rearranging data 2...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Rearranging data 2 Rearranging data ¡ Arrange relevant information within a single source data set ¡ A single observation in a source data set form multiple observations in the destination data set ¡ Multiple observation in a source data set form a single observation in the destination data set ¡ Converting variables into observations or observations into variables 3 Rearranging data ¡ Split a single observation into many (one to many) ¢ Array and DO-loop ¡ Combine multiple observations into a single observation (many to one) ¢ RETAIN statement ¢ FIRST.var and LAST.var automatic variables 4 One to many problem ¡ Observations that contain multiple occurrences of a medical diagnosis. ¢ Each observation represents one person. ¢ A person may have multiple medical diagnosis ¡ There are altogether over 500 different medical diagnosis (code 001 – 500) ¡ Tasks ¢ Create a table that shows how often each diagnosis occurs ¢ Create a list of patients who have both of 2 specific diagnoses 5 Data set ¡ The raw data file contains multiple occurrence of a medical diagnosis ¡ Create a SAS data set DIAGS from the raw data file * Example 8.1 read in data; data diags; infile 'C:\temp\dx.dat' missover; length id $3 dx1-dx5 $3; input id dx1-dx5; run; 6 ¡ Part of the data file 001 328 138 412 002 116 440 082 368 003 153 428 442 340 004 359 146 410 299 005 428 442 006 092 488 162 210 086 007 308 113 008 142 158 403 009 074 010 041 207 495 243 011 353 478 496 002 012 491 015 ... 7 Frequency table for diagnosis ¡ The first task is to create a table that shows how often each diagnosis occurs within the data set ¡ The difficulty is that the diagnoses are stored in 5 different variables in the data set ¡ On approach is to perform PROC FREQ on each of the 5 diagnoses and add the results of the 5 tables * Example 8.2 list frequency of diagnosis codes; * primitive method: list each of the 5 diagnoses and add up manually (!); proc freq data=diags; tables dx1-dx5/nopercent nocum; run; 8 dx1 Frequency---------------- 004 1 013 1 015 1 018 1 020 2 ... dx2 Frequency---------------- 007 1 008 1 009 1 011 2 015 3 ... dx3 Frequency---------------- 004 1 007 1 014 1 019 1 020 1 ... dx4 Frequency---------------- 002 1 006 1 020 1 023 1 030 1 ... dx5 Frequency---------------- 028 1 086 1 087 1 094 2 116 2 ... 9 Frequency table for diagnosis – an improved version * Example 8.2a list frequency of diagnosis codes; * modified from the primitive method; proc freq data=diags noprint; tables dx1/out=diag1; tables dx2/out=diag2; tables dx3/out=diag3; tables dx4/out=diag4; tables dx5/out=diag5; run; data diag_all; *add individual freq. tables by concatenation; set diag1(rename=(dx1=dx)) diag2(rename=(dx2=dx)) diag3(rename=(dx3=dx)) diag4(rename=(dx4=dx)) diag5(rename=(dx5=dx)) ; drop percent; run; proc freq data=diag_all; *data set of all diagnosis counts; table dx; weight count; *observations carry differet weight; run; 10 ¡ Perform analysis on each of the 5 diagnosis variable...
View Full Document

This note was uploaded on 02/09/2012 for the course STAT 1301 taught by Professor Smslee during the Spring '08 term at HKU.

Page1 / 41

Chapter 8. Rearranging data - 1 Rearranging data 2...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online