Date: Wed, 28 Jul 2004 21:57:23 -0400
Reply-To: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject: Re: Local MACRO VAR with code
Nicole wrote:
> I have a local macro variable that is created in a data _null with a
> call symput. Each time it goes through the loop, this macro var
> should become a new value. I noticed that this was not the case. The
> value of the local macro var reset for the first 6 by pass but than
> stay the same value for the remained of the loop.
>
> Anyone have any ideas why this is happening.
> Thanks
> I have a local macro variable that is created in a data _null with a
> call symput. Each time it goes through the loop, this macro var
> should become a new value. I noticed that this was not the case. The
> value of the local macro var reset for the first 6 by pass but than
> stay the same value for the remained of the loop.
>
> Anyone have any ideas why this is happening.
> Thanks
> Here is the code
> %Macro MonthlyAnalysis(obDates = RefDateList) ;
>
> proc sql noprint ;
>
> select count(*) as obsMos into :obsMos from &obDates ;
> select put(refdate, yymmdd4.) as Mo into :m1-:m9999 from
> &obDates;
>
> quit ;
>
> %global totobsmth;
> %let totobsmth=&obsMos;
>
> %do i = 1 %to &obsMos ;
>
> %global mth&i;
> %let mth&i=&&m&i;
>
> data _null_;
> call symput("perdate",put(sum(&&m&i + 100),Z4.));
> run;
> **more code here....
> %mend;
The SQL select sets an automatic macro variable SQLOBS. There is no need to
count(*).
Why copy m1-m* to global scope mth1-mth* ?
Why use a data _null_ to add 100 to Mo (as read from &obDates) ?
Why add 100 to date in representation yymmdd ? Do you want to just add 100
to the date ? or 1 to the month ? I will guess the month.
Does more code utilize the dates in yymmdd fashion ? If so, you probably
have to input to get back to SAS date value. It might be easier to leave
everything as a Date value (and not a string of characters that can be
interpreted as representing a date)
A simpler approach might be (there is probably a date interval specifier for
onemonth later)
If you need to use the m* date value in a certain representation in the %do
loop, you can use
%let dateInYmdForm = %sysfunc(putn(&&m&i,yymmdd));
select intnx('month', refdate,1)+refdate-intnx('month',refdate,0) into
:m1-:m9999 from &obDates;
%let nDates = &sqlobs;
%do i = 1 %to &nDates;
%put i=&i m&i=&&m&i;
%end;
--
Richard A. DeVenezia
http://www.devenezia.com/downloads/sas/samples/