Prev: Can't not start SAS
Next: Struggling to resolve an important data problem in SAS....please help.
From: Sdlentertd on 6 Aug 2010 15:36 I have this dataset Item Date A 8/2/2010 A 6/1/2009 A 5/1/2009 Z 2/2/2010 Z 1/1/2010 i NEED TO FLAG BASED in these conditions For A: in the last 10 months (Y or N) For Z: in the last 180 days (Y or N) Summary: Y or N of any of the above parameters are Y the output will be summary Y A Y Z N
From: Reeza on 6 Aug 2010 20:02 On Aug 6, 12:36 pm, Sdlentertd <sdlente...(a)gmail.com> wrote: > I have this dataset > Item Date > A 8/2/2010 > A 6/1/2009 > A 5/1/2009 > Z 2/2/2010 > Z 1/1/2010 > > i NEED TO FLAG BASED in these conditions > For A: in the last 10 months (Y or N) > For Z: in the last 180 days (Y or N) > Summary: Y or N of any of the above parameters are Y > > the output will be > summary Y > A Y > Z N Lookup the intnx and possibly the intck functions. Create two cutoff points cutoff_a=intnx('month', date(), 10); cutoff_b=intnx('day', date(), 180); You can subract dates directly, so use an if statement such as if item="A" and cutoff_a-date<0 then "Y" else if item="A" then "N" else if item="B" and cutoff_b-date<0 then "Y" else if item="B" then "N" else "U" Not sure about the <>. HTH, Reeza
From: Barry Schwarz on 8 Aug 2010 01:26 On Fri, 6 Aug 2010 12:36:10 -0700 (PDT), Sdlentertd <sdlentertd(a)gmail.com> wrote: >I have this dataset >Item Date >A 8/2/2010 >A 6/1/2009 >A 5/1/2009 >Z 2/2/2010 >Z 1/1/2010 > >i NEED TO FLAG BASED in these conditions >For A: in the last 10 months (Y or N) >For Z: in the last 180 days (Y or N) >Summary: Y or N of any of the above parameters are Y > >the output will be >summary Y >A Y >Z N One approach is a data step with a pair of do loops in tandem. The first loop reads until it is on the last observation of the current Item, determining if the flag should be Y or N as it goes. The second loop rereads the same observations and outputting the input variables plus the flag. The implied loop in the data step repeats the process until all the observations have been dealt with. -- Remove del for email
From: Sdlentertd on 9 Aug 2010 14:31 On Aug 7, 10:26 pm, Barry Schwarz <schwa...(a)dqel.com> wrote: > On Fri, 6 Aug 2010 12:36:10 -0700 (PDT), Sdlentertd > > > > > > <sdlente...(a)gmail.com> wrote: > >I have this dataset > >Item Date > >A 8/2/2010 > >A 6/1/2009 > >A 5/1/2009 > >Z 2/2/2010 > >Z 1/1/2010 > > >i NEED TO FLAG BASED in these conditions > >For A: in the last 10 months (Y or N) > >For Z: in the last 180 days (Y or N) > >Summary: Y or N of any of the above parameters are Y > > >the output will be > >summary Y > >A Y > >Z N > > One approach is a data step with a pair of do loops in tandem. The > first loop reads until it is on the last observation of the current > Item, determining if the flag should be Y or N as it goes. The second > loop rereads the same observations and outputting the input variables > plus the flag. The implied loop in the data step repeats the process > until all the observations have been dealt with. > > -- > Remove del for email- Hide quoted text - > > - Show quoted text - I am not very familiar with do loop.
From: gaurav Sood on 10 Aug 2010 10:49 On Aug 9, 11:31 pm, Sdlentertd <sdlente...(a)gmail.com> wrote: > On Aug 7, 10:26 pm, Barry Schwarz <schwa...(a)dqel.com> wrote: > > > > > > > On Fri, 6 Aug 2010 12:36:10 -0700 (PDT), Sdlentertd > > > <sdlente...(a)gmail.com> wrote: > > >I have this dataset > > >Item Date > > >A 8/2/2010 > > >A 6/1/2009 > > >A 5/1/2009 > > >Z 2/2/2010 > > >Z 1/1/2010 > > > >i NEED TO FLAG BASED in these conditions > > >For A: in the last 10 months (Y or N) > > >For Z: in the last 180 days (Y or N) > > >Summary: Y or N of any of the above parameters are Y > > > >the output will be > > >summary Y > > >A Y > > >Z N > > > One approach is a data step with a pair of do loops in tandem. The > > first loop reads until it is on the last observation of the current > > Item, determining if the flag should be Y or N as it goes. The second > > loop rereads the same observations and outputting the input variables > > plus the flag. The implied loop in the data step repeats the process > > until all the observations have been dealt with. > > > -- > > Remove del for email- Hide quoted text - > > > - Show quoted text - > > I am not very familiar with do loop.- Hide quoted text - > > - Show quoted text - Try this, it works perfectly fine I have created a sample data similar to what you had data test; input name $1. date ddmmyy10.; cards; A 8/2/2010 A 6/1/2009 A 5/1/2009 A 6/2/2010 Z 2/2/2010 Z 1/1/2010 Z 23/2/2010 ; run; The two variables a1 and b1 are just meant to see whether the between is working fine or not. proc sql; create table final as select name,date format=date9.,(intnx('month',date(),-10,'sameday')) as a1 format=date9.,(intnx('day',date(),-180,'sameday')) as b1 format=date9., (case when name = 'A' and date between date() and intnx('month',date(),-10,'sameday') then 'Y' else 'N' end) as A_flag, (case when name = 'Z' and date between date() and intnx('day',date(),-180,'sameday') then 'Y' else 'N' end) as B_flag, (case when calculated A_flag = 'Y' or calculated B_flag = 'Y' then 'Y' else 'N' end) as summary_flag from test; quit; But this does give the results that you desire.
|
Pages: 1 Prev: Can't not start SAS Next: Struggling to resolve an important data problem in SAS....please help. |