LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (March 2009, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 31 Mar 2009 01:55:18 -0700
Reply-To:     Chris Jones <chrisj75@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Chris Jones <chrisj75@GMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: Question on dates
Comments: To: sas-l@uga.edu
Content-Type: text/plain; charset=ISO-8859-1

On 31 Mar, 08:01, ravikumarp...@gmail.com wrote: > Hi all, > > I have a question on dates. > In the first macro, i am creating months. As per the macro my months > are: > Dec06,Jan07, Feb07. > > In the second macro , i need to create outmonth ( n=1 to 13). Here the > problem is, > > when i=1, month = Feb07 and outmonths starts from Dec06. > I want month = Feb07 and outmonths starts from Feb07 upto 12 months. > like wise i=2 , month = Jan07 and outmonths starts from Jan07 upto 12 > months > i=3, month = Dec06 and outmonths starts from Dec06 upto 12 months. > > Please help me in the above issue. > 1) > options mlogic mprint symbolgen; > %macro revs(); > data _null_; > %do i = 1 %to 3; > %global month&i; > %global mnt&i; > call symput("month&i",put(intnx('month',date(),%eval(-&i-24)), > yymmn6.)); > call symput("mnt&i",put(intnx('month',date(),%eval(-&i-24)), > monyy.)); > %end; > run; > %do j=1 %to 3; > %put &&month&j.; > %put &&mnt&j.; > %end; > %mend revs; > %revs; > > 2) > options mprint symbolgen ; > %macro revs(); > data _null_; > %do n = 1 %to 13; > %global outmon&n; > call symput("outmon&n",put(intnx('month',date(),%eval(+&i-24-5 > +&n.)),yymmn6.)); > %end; > run; > %do n=1 %to 13; > %put &&outmon&n.; > %end; > %mend revs; > %revs;

Do it all in a datastep, it'll be much easier...

data dates ; m1_seed = '01feb2007'd ; do m1 = 1 to 3 ; m1_date = intnx('month',m1_seed,1-m1,'beginning') ; /* roll back */ call symput('MONTH'||compress(m1),put(m1_date,monyy5.)) ; do m2 = 1 to 13 ; m2_date = intnx('month',m1_date,m2-1,'beginning') ; /* roll forward */ call symput('MONTH'||compress(m1||"_"||m2),put (m2_date,monyy5.)) ; output ; end ; end ; format m1_seed m1_date m2_date monyy5. ; run ;

%PUT &MONTH1 ; %PUT &MONTH1_1 ; %PUT &MONTH1_13 ;


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