|
George,
Does this do what you need?
%macro one(cy=);
data _null_;
call symputx('prev_cy_calc',%sysevalf(&cy-1));
call symputx('cystartdate',"01JAN%sysevalf(&cy-1)"d);
call
symputx('prev_cy_fromdate',put(intnx('months',"01JAN%sysevalf(&cy-1)"d,-
6,'B'),date9.));
call
symputx('prev_cy_todate',put(intnx('months',"01JAN%sysevalf(&cy-1)"d,-1,
'E'),date9.));
run;
%put;
%put *******************************************;
%put CY START DATE: 01JAN%sysevalf(&cy-1) ;
%put PREVIOUS CY #: &prev_cy_calc ;
%put PREVIOUS CY START DATE: &prev_cy_fromdate ; %put PREVIOUS CY END
DATE: &prev_cy_todate;
%put *******************************************;
%put;
%mend one;
%one(cy=2008)
%one(cy=2007)
%one(cy=2006)
%one(cy=2005)
%one(cy=2004)
%one(cy=2003)
%one(cy=2002)
%one(cy=2001)
%one(cy=2000)
%one(cy=1999)
%one(cy=1998)
Jack Clark
Senior Research Analyst
phone: 410-455-6256
fax: 410-455-6850
jclark@hilltop.umbc.edu
University of Maryland, Baltimore County
Sondheim Hall, 3rd Floor
1000 Hilltop Circle
Baltimore, MD 21250
Confidentiality Notice: This e-mail may contain information that is legally privileged and that is intended only for the use of the addressee(s) named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying of this e-mail, distribution, or action taken in reliance on the contents of this e-mail and/or documents attributed to this e-mail is strictly prohibited. If you have received this information in error, please notify the sender immediately by phone and delete this entire e-mail. Thank you.-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
George Joseph
Sent: Tuesday, June 09, 2009 1:10 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: MACRO not working for "00" to "98"
This macro should auto generate the correct Calender Year (CY) start
date
and two other dates that go back to the latter half of the previous
year. It
is failing since %sysevalf comes back with -1 for "00" but apparently my
conditional logic is not working either. So its creating 20098 and 20097
which are both invalid dates.
______________________________________________________
%macro one(cy);
data _null_;
%let prev_cy_calc=%sysevalf(&cy-1);
%if &cy="99" or &cy="98"
%then %do;
%let prev_cy_calc=%sysevalf(&cy-1);
%let cystartdate=01JAN19&prev_cy_calc;**should be 97 for CY=98, 99 for
CY 00
and so on***;
%end;
%if &cy="00" %then %do;
%let cystartdate=01JAN1999;**Since 00-1 is -1 it has to be
hardcoded****;
%end;
%else %do;
%let cystartdate=01JAN200&prev_cy_calc;
%end;
call
symputx('prev_cy_fromdate',put(intnx('months',"&cystartdate"d,-6,'B'),da
te9.));
call
symputx('prev_cy_todate',put(intnx('months',"&cystartdate"d,-1,'E'),date
9.));
run;
%put;
%put *******************************************;
%put CY START DATE: &cystartdate ;
%put PREVIOUS CY #: &prev_cy_calc ;
%put PREVIOUS CY START DATE: &prev_cy_fromdate ;
%put PREVIOUS CY END DATE: &prev_cy_todate;
%put *******************************************;
%put;
%mend one;
options mprint mcompilenote=all symbolgen;
%one(08)
%one(07)
%one(06)
%one(05)
%one(04)
%one(03)
%one(02)
%one(01)
%one(00)
%one(99)
%one(98)
|