| Date: | Fri, 15 Aug 1997 09:30:27 -0700 |
| Reply-To: | Greg Silva <NO_SPAM_RN2380@EMAIL.SPS.MOT.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Greg Silva <NO_SPAM_RN2380@EMAIL.SPS.MOT.COM> |
| Organization: | Semiconductor Products Sector |
| Subject: | Re: Macro Guru Consolidation Challenge |
| Content-Type: | text/plain; charset=us-ascii |
I hope this is what you had in mind:
%macro getmon(smonth, syear, curmonth) ;
%* Assume, to make things easier, that the start month (smonth) ;
%* is entered as a number. ;
%let mon1 = jan;
%let mon2 = feb;
%let mon3 = mar;
%let mon4 = apr;
%let mon5 = may;
%let mon6 = jun;
%let mon7 = jul;
%let mon8 = aug;
%let mon9 = sep;
%let mon10 = oct;
%let mon11 = nov;
%let mon12 = dec;
%* Set up the first month. ;
%let startmon =&&mon&smonth ;
%* Generate the 24 months based on the start month (smonth). ;
%* Note that you could make this a parameter as well. ;
%do i = 1 %to 24;
%* Resolve testmon to mon1, then resolve mon1 to jan. ;
%let testmon = &&startmon ;
%* Resolve to jan97 ;
%let testmon = &testmon&syear ;
%if &curmonth eq &testmon %then %let ol&testmon = %str(match
found);
%else %let ol&testmon =%str( no
match);
%* A test to see if the current month is flagged. ;
%if &&ol&testmon eq %str(match found) %then %put
curmonth=&curmonth ;
%* build the next month. ;
%let smonth = %eval(&smonth + 1) ;
%if (&smonth < 13) %then %let startmon=&&mon&smonth ;
%else %do ;
%let smonth = 1 ;
%let startmon =&mon1 ;
%let syear = %eval(&syear + 1) ;
%* Make it year 2000 compliant. :) ;
%if (&syear < 10) %then %let syear = 0&syear ;
%if (&syear > 99) %then %let syear = 00 ;
%end ;
%end ;
%mend ;
%getmon(2, 96, mar97) ;
TERJESON Mark wrote:
>
> * Dear macro guru types,
> I am drawing a blank as to a way to consolidate
> this repetative code into a %DO loop or something.
> I really would like an iterative process where 24
> months could be specified, such as jul95-jun97. ;
>
> * ...hopefully in open code or in a macro. yes, it
> could be done in a data step and output with
> SYMPUT()s, but I was curious to see if it could be
> done with macro code only. ;
>
> %let curmonth = mar97;
>
> .
> .
> .
> %if &curmonth eq feb97 %then %let olfeb97=%str(match found);
> %else %let olfeb97=%str( no match);
> %if &curmonth eq mar97 %then %let olmar97=%str(match found);
> %else %let olmar97=%str( no match);
> %if &curmonth eq apr97 %then %let olapr97=%str(match found);
> %else %let olapr97=%str( no match);
> %if &curmonth eq may97 %then %let olmay97=%str(match found);
> %else %let olmay97=%str( no match);
> .
> .
> .
>
> * where one copy can be used in a loop patching the 3 locations with
> increasing months;
>
> %if &curmonth eq ????? %then %let ol?????=%str(match found);
> %else %let ol?????=%str( no match);
>
> PS: I know the %STR function isn't required with what is showing here,
> but in the
> real application it is required due to other content.
>
> for those willing to look at this, thanks in advance!
>
> Mark Terjeson
> Office of Forecasting and Policy Analysis
> DSHS Headquarters
> State of Washington
> terjemw@dshs.wa.gov
|