Re: rollup

  • Follow


Explain your rules in english.  This definitely isn't the easiest way to do
this.

First off, if your &enddate is an actual date value, then just use month( )
to determine which month it's in.

Second, presumably you can use INTNX to define startday/endday.  If you
explain your rules better we can help define what arguments to supply to
give you a general solution.  No reason to solve this only for November.

Third, the other half of your code will be solved using year( ) along with
the startday and/or endday, if I understand it correctly.

-Joe

On Mon, Jan 18, 2010 at 10:55 PM, William Shakespeare <
shakespeare_1040@hotmail.com> wrote:

> I have a rollup in a data step that looks like this:
>
> %let enddate='31NOV09'd;
>
> data want;
>  set have;
>  if substr(put(&enddate,date9.),3,3)='NOV' then do;
>    if substr(put(trans_date,date9.),3,3)='DEC' or
>    if substr(put(trans_date,date9.),3,3)='JAN' or
>    if substr(put(trans_date,date9.),3,3)='FEB'
>    then do;
>    startday='01JAN;
>    enday='28FEB'
>   end;
>  end;
>
> if not missing(startday) & not missing(endday) then do;
>  if datepart(trans_date)>=input(cats(startday,2007),date9.) &
>  if datepart(trans_date)<=input(cats(endday,2007),date9.)
>  then do;
>    sales_2007+sales;
>  end;
> end;
>
> if not missing(startday) & not missing(endday) then do;
>  if datepart(trans_date)>=input(cats(startday,2008),date9.) &
>  if datepart(trans_date)<=input(cats(endday,2008),date9.)
>  then do;
>    sales_2008+sales;
>  end;
> end;
>
> run;
>
> This works fine except that it excludes 29FEB08.  Is there an easy way of
> incrementing endday by one for leap years without rewriting all this code?
> I want to expand this code to cover other 3 month periods which is easy
> enough but the leap year thing has got me stumped.  Be nice if I could get
> away with: if datepart(trans_date)<=input(cats(endday+1,2008),date9.) Maybe
> best if I explicitly specified if datepart(trans_date)<='29FEB09'd for
> 2008.
>  Suggestions?
>
0
Reply snoopy369 (1752) 1/19/2010 5:27:26 AM

freelance writer


0
Reply user137 (56) 5/13/2011 6:58:17 PM


freelance writer
0
Reply CaseyMadden28 5/13/2011 6:58:20 PM

freelance writer


0
Reply user137 (56) 5/13/2011 8:04:51 PM

freelance writer
0
Reply PetraGreer 5/13/2011 8:04:55 PM

freelance writer


0
Reply user137 (56) 5/13/2011 8:17:41 PM

freelance writer
0
Reply MartinVanessa28 5/13/2011 8:17:45 PM

freelance writer


0
Reply user137 (56) 5/13/2011 11:21:25 PM

freelance writer
0
Reply ReynaKent 5/13/2011 11:21:29 PM

freelance writer


0
Reply user137 (56) 5/14/2011 12:06:22 AM

freelance writer
0
Reply ParkMartha 5/14/2011 12:06:25 AM

freelance writer


0
Reply user137 (56) 5/14/2011 1:17:04 AM

freelance writer
0
Reply Harriett26MCCONNELL 5/14/2011 1:17:08 AM

12 Replies
214 Views

(page loaded in 0.116 seconds)

Similiar Articles:




7/20/2012 4:35:14 AM


Reply: