Prev: HP Unix Admin -- AZ
Next: DOW losing 600 points in a few minutes: no technical glitch, no foul play, but a natural cause?
From: Sdlentertd on 7 May 2010 14:35 I have this dataset..... Drug Store Date AAA 1111 01/05/2010 BBB 1112 04/05/2010 AAA 1112 04/05/2009 CCC 1113 02/02/2009 I need to list all stores and flag them according to Drug and if AAA and within last 10 month (from today) then Flag, if BBB and within last 180 days then flag, if CCC and within last 180 days then flag, Date is in this format: DATETIME22.3 Results: Store AAA BBB CCC 1111 Y N N 1112 N Y N 1113 N N N Thank you
From: Arthur Tabachneck on 7 May 2010 19:48 I was hoping that someone better with dates, than me, would have responded. But, since they haven't, I THINK the following may do what you want: data have; input Drug $ Store Date anydtdtm10.; format date DATETIME22.3; drug_date=catt(drug,date); cards; AAA 1111 01/05/2010 BBB 1112 04/05/2010 AAA 1112 04/05/2009 CCC 1113 02/02/2009 ; proc sort data=have; by store; run; proc transpose data=have out=need (drop=_:); var drug_date; id drug; by store; run; data want; set need; format aaa bbb ccc $1.; if intnx('month', today(), -10, 'sameday') le datepart( input(substr(aaa,4),best12.)) then aaa="Y"; else aaa="N"; if intnx('day', today(), -180, 'sameday') le datepart( input(substr(bbb,4),best12.)) then bbb="Y"; else bbb="N"; if intnx('day', today(), -180, 'sameday') le datepart( input(substr(ccc,4),best12.)) then ccc="Y"; else ccc="N"; run; HTH, Art ------------ On May 7, 2:35 pm, Sdlentertd <sdlente...(a)gmail.com> wrote: > I have this dataset..... > Drug Store Date > AAA 1111 01/05/2010 > BBB 1112 04/05/2010 > AAA 1112 04/05/2009 > CCC 1113 02/02/2009 > > I need to list all stores and flag them according to Drug > and if AAA and within last 10 month (from today) then Flag, if BBB and > within last 180 days then flag, if CCC and within last 180 days then > flag, > Date is in this format: DATETIME22.3 > Results: > Store AAA BBB CCC > 1111 Y N N > 1112 N Y N > 1113 N N N > > Thank you
From: Patrick on 9 May 2010 00:21
Hi Just another version based on what Art already provided. HTH Patrick data have; infile datalines truncover; input Drug $ Store $ DT:anydtdtm10.; format DT datetime22.3; x=today()-datepart(DT); put drug= store= x=; datalines; AAA 1111 01/05/2010 BBB 1112 04/05/2010 AAA 1112 04/05/2009 CCC 1113 02/02/2009 CCC 1113 02/02/2010 ; run; data FlagIt; set have; flag=0; select(Drug); when('AAA') do; if intnx('month', today(),-10, 'sameday') le datepart(DT) then flag=1; end; when('BBB','CCC') do; if today()-datepart(DT)<=180 then flag=1; end; otherwise flag=-1; end; run; proc sql; create view V_MaxFlag as select store ,drug ,max(flag) as flag from FlagIt group by store,drug ; quit; proc format; value flag -1='?' .,0 ='N' 1 ='Y' ; run; proc transpose data=V_MaxFlag out=Want(drop=_name_); by store; id drug; format flag flag.; var flag; run; proc print data=want; run; |