资源描述
Click to edit Master title style,Click to edit Master text styles,Second Level,Third Level,Fourth Level,Fifth Level,*,*,*,Longitudinal Data Techniques:,Looking Across Observations,Ronald Cody,Ed.D.,Robert Wood Johnson Medical School,A Typical Longitudinal Data Set,PATNO DATE DOBHRSBPDBP,001 10/21/1997 10/21/1946 48 128 74,001 02/01/1998 44 126 70,001 11/04/1998 52 130 76,001 11/07/1998 54 132 78,003 11/11/1998 09/08/1955 52 140 80,007 04/04/1998,008 03/22/1998 02/08/1980 58 144 72,008 04/21/1998 66 144 74,012 05/06/1998 80 120 80,013 11/11/1998 11/09/1930 100 180 108,013 11/18/1998 90 170 98,123 01/28/1998 01/01/1944 80 180 96,123 05/04/1998 80 178 90,Common Data Processing Requirements,Extract the first or last visit for a subject,Copy information from the first visit to subsequent visits,Compute intra-patient statistics such as mean,median,minimum,or maximum,Common Data Processing Requirements,Count the number of visits per patient,Compute differences of variables between visits,Make decisions on the current visit,based on information from a future visit,Selecting the First(or last)Visit for Each Patient,PROC SORT DATA=LABS;,BY PATNO DATE;,RUN;,DATA FIRST;,SET LABS;,BY PATNO;,IF FIRST.PATNO;,RUN;,Listing of FIRST,PATNO DATE DOB HR SBP DBP,001 10/21/1997 10/21/1946 48 128 74,003 11/11/1998 09/08/1955 52 140 80,007 04/04/1998 .,008 03/22/1998 02/08/1980 58 144 72,012 05/06/1998 .80 120 80,013 11/11/1998 11/09/1930 100 180 108,123 01/28/1998 01/01/1944 80 180 96,354 04/12/1998 07/07/1955 90 210 110,554 06/08/1998 09/12/1944 48 108 66,888 01/01/1998 03/14/1922 46 110 68,DATA LAST;,SET LABS;,BY PATNO;,IF LAST.PATNO;,RUN;,Adding DOB to the Second Through the Last Observation for Each Patient,PROC SORT DATA=LABS;,BY PATNO DATE;,RUN;,DATA LAB2;,SET LAB;,BY PATNO;,RETAIN OLD_DOB;,IF,FIRST.PATNO,THEN OLD_DOB=DOB;,ELSE DOB=OLD_DOB;,RUN;,DOB Added to Observations,PATNO DATE DOBHRSBP DBP,001 10/21/1997 10/21/1946 48 128 74,001 02/01/1998 10/21/1946 44 126 70,001 11/04/1998 10/21/1946 52 130 76,001 11/07/1998 10/21/1946 54 132 78,003 11/11/1998 09/08/1955 52 140 80,007 04/04/1998,008 03/22/1998 02/08/1980 58 144 72,008 04/21/1998 02/08/1980 66 144 74,012 05/06/1998 80 120 80,013 11/11/1998 11/09/1930 100 180 108,013 11/18/1998 11/09/1930 90 170 98,123 01/28/1998 01/01/1944 80 180 96,123 05/04/1998 01/01/1944 80 178 90,Computing Differences Between Observations,(using RETAIN),*DIFFERENCE BETWEEN FIRST AND LAST VISIT;,DATA DIFFERENCE;/*NOT USING V7?*/,SET LAB2;,BY PATNO;,*REMOVE PATIENTS WITH ONE VISIT;,IF FIRST.PATNO AND LAST.PATNO THEN DELETE;,RETAIN R_HR R_SBP R_DBP;,IF FIRST.PATNO THEN DO;,R_HR =HR;,R_SBP=SBP;,R_DBP=DBP;,END;,(continued),Computing Differences Between Observations,(using RETAIN),(continued),IF LAST.PATNO THEN DO;,DIFF_HR =HR-R_HR;,DIFF_SBP=SBP-R_SBP;,DIFF_DBP=DBP-R_DBP;,OUTPUT;,END;,DROP R_:;,RUN;,Computing Differences Between Observations,(using RETAIN),Listing of data set difference,D D,D I I,I F F,P F F F,A D F _ _,O T A D S D _ S D,b N T O H B B H B B,s O E B R P P R P P,1 001 11/07/1998 10/21/1946 54 132 78 6 4 4,2 008 04/21/1998 02/08/1980 66 144 74 8 0 2,3 013 11/18/1998 11/09/1930 90 170 98 -10 -10 -10,4 123 05/04/1998 01/01/1944 80 178 90 0 -2 -6,Computing Differences Between the First and Last Visit(using LAG),DATA DIFF3;,SET LABS2;,BY PATNO;,*Remove patients with one visit;,IF FIRST.PATNO AND LAST.PATNO THEN DELETE;,IF FIRST.PATNO OR LAST.PATNO THEN DO;,DIFF_HR =HR-LAG(HR);,DIFF_SBP=SBP-LAG(SBP);,DIFF_DBP=SBP-LAG(DBP);,END;,IF LAST.PATNO THEN OUTPUT;,RUN;,Note:About the only time I ever executed a LAG function,conditionally(on purpose),Computing Differences Between Observations,(using the LAG function),*DIFFERENCES BETWEEN ALL VISITS;,DATA DIFF2;,SET LAB2;,BY PATNO;,DIFF_HR=HR-LAG(HR);,*Alternative(below)using the DIF function;,DIFF_SBP=DIF(SBP);,DIFF_DBP=DIF(DBP);,IF NOT FIRST.PATNO THEN OUTPUT;,RUN;,Computing Differences Between Observations,(using the LAG function),Listing of data set diff2,D D,D I I,I F F,P F F F,A D F _ _,O T A D S D _ S D,b N T O H B B H B B,s O E B R P P R P P,1 001 02/01/1998 10/21/1946 44 126 70 -4 -2 -4,2 001 11/04/1998 10/21/1946 52 130 76 8 4 6,3 001 11/07/1998 10/21/1946 54 132 78 2 2 2,4 008 04/21/1998 02/08/1980 66 144 74 8 0 2,5 013 11/18/1998 11/09/1930 90 170 98 -10 -10 -10,6 123 05/04/1998 01/01/1944 80 178 90 0 -2 -6,Counting the Number of Observations in Each BY Group,DATA COUNT_IT;,SET LABS2,(KEEP=PATNO),;,BY PATNO;,IF FIRST.PATNO THEN N_VISITS=1;,ELSE N_VISITS+1;,IF LAST.PATNO THEN OUTPUT;,RUN;,Listing of data set COUNT_IT,Obs PATNO N_VISITS,1 001 4,2 003 1,3 007 1,4 008 2,5 012 1,6 013 2,7 123 2,Using PROC FREQ to Output a Data Set Containing Counts,PROC FREQ DATA=LABS2,NOPRINT,;,TABLES PATNO/,OUT=COUNTS(KEEP=PATNO COUNT,RENAME=(COUNT=N_VISITS);,RUN;,Listing of data set COUNTS,Obs PATNO N_VISITS,1 001 4,2 003 1,3 007 1,4 008 2,5 012 1,6 013 2,7 123 2,Creating Summary Data Sets Using PROC MEANS,PROC MEANS DATA=LABS2,NWAY NOPRINT,;,CLASS PATNO;,VAR HR
展开阅读全文