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 2005, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 16 Jun 2005 14:23:05 -0700
Reply-To:   "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Terjeson, Mark (IM&R)" <Mterjeson@RUSSELL.COM>
Subject:   Re: How to covert macro variable to number and assign back to macro variable
Comments:   To: Mark <joystar.jin@GMAIL.COM>
Content-Type:   text/plain; charset="US-ASCII"

Hi Matt,

The first thing to remember is that ALL macro stuff is string text as string substitution. Therefor chop out the year characters out of the string and since the macro stuff is string the %eval() function will convert the string internally and perform the arithmetic and then convert the result back to string being returned.

%macro test(MONTH); %let m=%eval(%substr(&MONTH,1,4)+2)%substr(&MONTH,5,2); %put &m; %mend test;

%test(200405);

Hope this is helpful.

Mark Terjeson Senior Programmer Analyst, IM&R Russell Investment Group

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mark Sent: Thursday, June 16, 2005 2:15 PM To: SAS-L@LISTSERV.UGA.EDU Subject: How to covert macro variable to number and assign back to macro variable

I need to pass a month variable into my macro. Then I want to convert it to number, and increase it by 200.

Say if the value is 200405, then after pass in into macro I want to get 200605 and assign it to a new macro variable.

%macro test(MONTH) m=&MONTH; %mend test;

For instance, in above code, &MONTH contain value of 200405. I want to get 200605(200405+200) and assign it to a new macro variable(&MONTH_NEW).

Thanks,

Matt


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