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?
>
|