Presentation is loading. Please wait.

Presentation is loading. Please wait.

Saving Data Steps with the Proc SQL Self-join Yan Wang Population Health Research Unit (PHRU) Dalhousie University.

Similar presentations


Presentation on theme: "Saving Data Steps with the Proc SQL Self-join Yan Wang Population Health Research Unit (PHRU) Dalhousie University."— Presentation transcript:

1 Saving Data Steps with the Proc SQL Self-join Yan Wang Population Health Research Unit (PHRU) Dalhousie University

2 The Task ObsID indexdate exdate 11 28MAR2001. 21 28APR2001 28APR2001 31 29JAN2004. 42 28JUN1997. 52 02JAN1998 02JAN1998 62 08JAN1998 08JAN1998 7 2 15FEB1998 15FEB1998 8 2 23FEB1998. 9 2 11JUN1999. One data set with 2 dates: indexdate and exdate For each individual, subsetting records whose indexdate in the 120 days before or 90 days after exdate

3 proc sql; select a.*, (-90<= b.exdate-a.indexdate <=120) as diff from temp as a, temp as b where a.ID=b.ID; quit; Obs ID indexdate exdate diff 1 1 28MAR2001. 0 2 1 28APR2001 28APR2001 0 3 1 29JAN2004. 0 4 1 28MAR2001. 1 5 1 28APR2001 28APR2001 1 6 1 29JAN2004. 0 7 1 28MAR2001. 0 8 1 28APR2001 28APR2001 0 9 1 29JAN2004. 0 Obs ID indexdate exdate 1 1 28MAR2001. 2 1 28APR2001 28APR2001 3 1 29JAN2004. Obs ID indexdate exdate 1 1 28MAR2001. 2 1 28APR2001 28APR2001 3 1 29JAN2004. Comparing

4 Obs ID indexdate exdate diff 1 1 28MAR2001. 0 21 2 11JUN1999. 0 2 1 28APR2001 28APR2001 0 22 2 28JUN1997. 0 3 1 29JAN2004. 0 23 2 02JAN1998 02JAN1998 1 4 1 28MAR2001. 1 24 2 08JAN1998 08JAN1998 1 5 1 28APR2001 28APR2001 1 25 2 15FEB1998 15FEB1998 1 6 1 29JAN2004. 0 26 2 23FEB1998. 1 7 1 28MAR2001. 0 27 2 11JUN1999. 0 8 1 28APR2001 28APR2001 0 28 2 28JUN1997. 0 9 1 29JAN2004. 0 29 2 02JAN1998 02JAN1998 1 10 2 28JUN1997. 0 30 2 08JAN1998 08JAN1998 1 11 2 02JAN1998 02JAN1998 0 31 2 15FEB1998 15FEB1998 1 12 2 08JAN1998 08JAN1998 0 32 2 23FEB1998. 1 13 2 15FEB1998 15FEB1998 0 33 2 11JUN1999. 0 14 2 23FEB1998. 0 34 2 28JUN1997. 0 15 2 11JUN1999. 0 35 2 02JAN1998 02JAN1998 0 16 2 28JUN1997. 0 36 2 08JAN1998 08JAN1998 0 17 2 02JAN1998 02JAN1998 1 37 2 15FEB1998 15FEB1998 0 18 2 08JAN1998 08JAN1998 1 38 2 23FEB1998. 0 19 2 15FEB1998 15FEB1998 1 39 2 11JUN1999. 0 20 2 23FEB1998. 1 40 2 28JUN1997. 0 41 2 02JAN1998 02JAN1998 0 42 2 08JAN1998 08JAN1998 0 43 2 15FEB1998 15FEB1998 0 44 2 23FEB1998. 0 45 2 11JUN1999. 0

5 proc sql; select distinct a.*, sum(-90 0 as index from temp as a, temp as b where a.ID=b.ID group by a.ID, a.indexdate; quit; Obs ID indexdate exdate index 1 1 28MAR2001. 1 2 1 28APR2001 28APR2001 1 3 1 29JAN2004. 0 4 2 28JUN1997. 0 5 2 02JAN1998 02JAN1998 1 6 2 08JAN1998 08JAN1998 1 7 2 15FEB1998 15FEB1998 1 8 2 23FEB1998. 1 9 2 11JUN1999. 0 Identifying

6 proc sql; create table tp as select distinct a.*, sum(-90 0 as index from temp as a, temp as b where a.ID=b.ID group by a.ID, a.indexdate having index = 1; quit; Subsetting Obs ID indexdate exdate index 1 1 28MAR2001. 1 2 1 28APR2001 28APR2001 1 3 2 02JAN1998 02JAN1998 1 4 2 08JAN1998 08JAN1998 1 5 2 15FEB1998 15FEB1998 1 6 2 23FEB1998. 1

7 Reference Subsetting SAS ® Data Set by Using PROC SQL Self-join with Compound Key Zizhong Fan, Westat, Rockville, MD http://www2.sas.com/proceedings/sugi29/065-29.pdf

8


Download ppt "Saving Data Steps with the Proc SQL Self-join Yan Wang Population Health Research Unit (PHRU) Dalhousie University."

Similar presentations


Ads by Google