Prev: Looking for Stockist and Distributors for our fast moving Nutraceutical and Baby food products
Next: PROC TABULATE question
From: data _null_; on 29 Apr 2010 13:22 On Apr 29, 11:46 am, arun <aruku...(a)gmail.com> wrote: > Hi all, > > here is the situation Plz help. > > I will be getting the data with 2 weeks or 3 weeks data from sql such > as > > variant date > 1 04/12 > 2 04/13 > 3 04/14 > . > > . > . > continously till the end of the two weeks then i need to seperate the > data into seperate weeks and send them to diff outputs > > i am using this > > proc sort data = aru.a > by variant week; > run; > > data aru.1a; > set aru.a; > by variant week > tempdate = lag(week); > if first.variant then tempdata = .; > retain flag; > if first.variant then flag = 1; > if week ne tempdate then flag = flag +1; > run; > > select; > when 1>=flag>=7 and _n_ ne 0 then output sar_1; > when 8>=flag>=14 and _n_ ne 0 then output sar_2; > when 15>=flag>=21 and _n_ ne 0 then output sar_3; > when 22>=flag>=28 and _n_ ne 0 then output sar_4; > when 29>=flag>=35 and _n_ ne 0 then output sar_5; > otherwise; > end; > > Now the issue is there are some situations where I will be missing > some days for the weeks in between such as > from 04/12 it will jump to 04/14 where it will take the data of the > day of next week to this week > > now is there any way we could see that if it misses then it should > take the output of only 6 days to the dataset like first checking for > the first 7 consecutive days then execute or any other way. > > I don't want to run the code manually 2 - 3 times so I am creating a > macro with do loop at the bottom so that it can run. > > Please help me on this if possible. Create a new variable "WEEK" using INTNX function to group the dates. This example uses Monday as the first day of the week. 'WEEK.2' data test; input variant date:mmddyy.; format date mmddyy.; week = intnx('week.2',date,0); format week mmddyy.; cards; 1 04/11/2010 1 04/12/2010 2 04/13/2010 3 04/14/2010 3 04/15/2010 3 04/16/2010 3 04/17/2010 3 04/18/2010 3 04/19/2010 3 04/20/2010 ;;;; run; proc print; run; |