Prev: How to select at least one of the variables that is larger than a certain value
Next: 2 way and 3 way R structures
From: Al on 16 Jul 2010 15:28 Dear All; This is what i have data have; input pat meds $ stdt spdt; datalines; 111 ABC 1 . 111 CBF 1 140 111 DFS 141 170 111 NAT 65 . 111 MAN 160 165 111 MAA 6 223 ; run; range for week 20 (1-143),week 24 (1-171),week 23 (1-227) and the rules are if stdt = 1 and spdt = . then it should be counted under week20 , week24 and week32 if stdt has started at week 20 and kept on progressing it has stopped (spdt) he counted under week20,week24 and week32 if stdt has started at week 20 and stopped at week 24 it has to be counted under week20,week24 and so on i know i am being very crude in explaining the issue here ,so here is the graphical presentation pat med week20 week24 week32 (1-143) (1-171) (1-227) 111 ABC (1)-------------------------------------------------------------------------------- > 111 CBF (1)------------------->(140) 111 DFS (141)------>170 111 NAT (65)-------------------------------------------------------------------------- > 111 MAN (160)------ >(165) 111 MAA (6)---------------------------------------------------------------- >(223) ideally ,output should like pat week20 week24 week32 111 5 4 3 Thanks in advance Al
From: Richard A. DeVenezia on 19 Jul 2010 14:24
On Jul 16, 3:28 pm, Al <ali6...(a)gmail.com> wrote: > Dear All; > > This is what i have > > data have; > input pat meds $ stdt spdt; > > datalines; > 111 ABC 1 . > 111 CBF 1 140 > 111 DFS 141 170 > 111 NAT 65 . > 111 MAN 160 165 > 111 MAA 6 223 > ; > run; > > range for week 20 (1-143),week 24 (1-171),week 23 (1-227) and the > rules are > > if stdt = 1 and spdt = . then it should be counted under week20 , > week24 and week32 > > if stdt has started at week 20 and kept on progressing it has stopped > (spdt) he counted under week20,week24 and week32 > > if stdt has started at week 20 and stopped at week 24 it has to be > counted under week20,week24 > > and so on > > i know i am being very crude in explaining the issue here ,so here is > the graphical presentation > > pat med week20 > week24 week32 > (1-143) > (1-171) (1-227) > > 111 ABC > (1)-------------------------------------------------------------------------------- > > 111 CBF (1)------------------->(140) > 111 DFS (141)------>170 > 111 NAT > (65)-------------------------------------------------------------------------- > > 111 MAN (160)------>(165) > > 111 MAA > (6)---------------------------------------------------------------- > > >(223) > > ideally ,output should like > > pat week20 week24 week32 > 111 5 4 3 > > Thanks in advance > Al Al: The explanation was pretty vague. Here is some sample code that matches your sample output/ ---------- data have; input pat meds $ stdt spdt; datalines; 111 ABC 1 . 111 CBF 1 140 111 DFS 141 170 111 NAT 65 . 111 MAN 160 165 111 MAA 6 223 ; run; data activity; set have; if STDT > 0; GUARD = MIN (SPDT,1e10); if STDT <= GUARD; if ( STDT < 1 or 1 <= STDT <= 143 ) and (GUARD > 143 or 1 <= GUARD <= 143) then c143 = 1; if ( STDT < 144 or 144 <= STDT <= 171 ) and (GUARD > 171 or 144 <= GUARD <= 171) and c143 then c171 = 1; if ( STDT < 171 or 171 <= STDT <= 227 ) and (GUARD > 227 or 172 <= GUARD <= 227) and c171 then c227 = 1; run; ---------- Richard A. DeVenezia http://www.devenezia.com |