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