Prev: reading XDR format with SAS
Next: lag by group
From: Al on 14 Jul 2010 20:09 Dear All: This is the dataset i have data have; input pat meds $ stdt spdt; cards; 111 ABC 1 . 111 CDE 130 150 111 NNN 132 140 111 GHI 160 170 111 LMN 165 . 111 OPQ 168 . 222 ABC 1 . 222 CBM 130 140 222 AAA 135 140 222 KHA 1 . ; run; I am trying to count the number of meds at different time points and create three fields week 20,week 24 and diff based on the following. number of meds at week 20 = number of meds with no spdt and stdt = 1 + any meds between (127(stdt) to 154(spdt)) + any meds between (127(stdt) to 154(spdt)) and spdt = . number of meds at week 24 = number of meds with no spdt and stdt = 1 + any meds between (155(stdt) to 182(spdt)) + any meds between (155(stdt) to 182(spdt)) and spdt = . Ideally, this is what i am tring to get to ,one record per pat Pat week 20 week 24 diff(week 24-week 20) 111 3 4 1 222 4 2 -2 I hope i wasnt confusing .. Thanks in advance .. Al
From: Patrick on 15 Jul 2010 08:35 Hi Al Not that I really understand what I'm doing here - but the following code gives you the result you're looking for: data have; input pat meds $ stdt spdt; cards; 111 ABC 1 . 111 CDE 130 150 111 NNN 132 140 111 GHI 160 170 111 LMN 165 . 111 OPQ 168 . 222 ABC 1 . 222 CBM 130 140 222 AAA 135 140 222 KHA 1 . ; run; data want(keep=pat week20 week24 diff); set have; by pat; if first.pat then do; week20=0; week24=0; end; if (spdt=. and stdt = 1) or (stdt>=127 and stdt<=154) then week20+1; if (spdt=. and stdt = 1) or (stdt>=155 and stdt<=182) then week24+1; if last.pat then do; diff=sum(week24,-week20); output; end; run; proc print data=want noobs; run; HTH Patrick
|
Pages: 1 Prev: reading XDR format with SAS Next: lag by group |