LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2009, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 9 Jun 2009 15:11:17 -0400
Reply-To:     Jack Clark <jclark@HILLTOP.UMBC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Clark <jclark@HILLTOP.UMBC.EDU>
Subject:      Re: MACRO not working for "00" to "98"
Comments: To: George Joseph <gjman@hotmail.com>
In-Reply-To:  <COL119-W75317BD37A2AFB1275493A0440@phx.gbl>
Content-Type: text/plain; charset="us-ascii"

George,

One way would be to add a second parameter on your macro call...

%one (cy=2008,cy2=08)

then use the two values when most convenient.

If you only want to have the 2-digit value as a parameter, you could create the 4-digit value as a second macro variable inside the macro. As Chang said, read up on the YEARCUTOFF option if you do this.

%macro one(cy=);

data _null_;

call symput('year4',put(year(mdy(01,01,&cy.)),4.));

run;

data _null_;

call symputx('prev_cy_calc',&year4.-1);

call symputx('cystartdate',"01JAN%sysevalf(&year4-1)"d);

call symputx('prev_cy_fromdate',put(intnx('months',"01JAN%sysevalf(&year4-1)" d,-6,'B'),date9.));

call symputx('prev_cy_todate',put(intnx('months',"01JAN%sysevalf(&year4-1)"d, -1,'E'),date9.));

run;

%put;

%put *******************************************;

%put CY START DATE: 01JAN%sysevalf(&year4-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=08)

%one(cy=07)

%one(cy=06)

%one(cy=05)

%one(cy=04)

%one(cy=03)

%one(cy=02)

%one(cy=01)

%one(cy=00)

%one(cy=99)

%one(cy=98)

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

________________________________

From: George Joseph [mailto:gjman@hotmail.com] Sent: Tuesday, June 09, 2009 2:18 PM To: Jack Clark; sas-l@listserv.uga.edu Subject: RE: MACRO not working for "00" to "98"

Thanks!! This works really well.

The reason I used 08 instead of 2008 is that's who we refer to our data sets. So its "CY 0h-Eight" and that helps out other folks who will be looking at the code. We dont say "Two Thousand and Eight" unless we are referring to a real Date.

Is there any way I can get it to work with 08 rather than 2008?

-G

> Subject: RE: MACRO not working for "00" to "98" > Date: Tue, 9 Jun 2009 14:01:02 -0400 > From: jclark@hilltop.umbc.edu > To: gjman@HOTMAIL.COM; SAS-L@LISTSERV.UGA.EDU > > 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)


Back to: Top of message | Previous page | Main SAS-L page