| Date: | Wed, 24 Jan 2007 14:33:47 -0600 |
| Reply-To: | "Paul A. Thompson" <paul@WUBIOS.WUSTL.EDU> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Paul A. Thompson" <paul@WUBIOS.WUSTL.EDU> |
| Subject: | Re: Macro Variable Problem (or should I say, coder problem) |
|
| In-Reply-To: | <51A3B7155A485548A47D068A9793C4FF16F4E941@m-ncid-1.ncid.cdc.gov> |
| Content-Type: | text/plain; charset="us-ascii" |
That's a problem with CALL EXECUTE. You can't use it for this sort of
thing. When you are doing that sort of macro assignment, CALL EXECUTE has a
problem. I don't know a work-around but one might exist.
Here is a better approach. In this approach, you go through the data and
make "macro arrays" by appending a number to the macro variable. Then, you
loop through the values.
%macro _overall;
Data _NULL_;
Set source;
Cnt+1;
Call symput(compress("_parma"||put(cnt,3.)),
compress(put(vala,best8.)));
Call symput(compress("_parmb"||put(cnt,3.)),
compress(put(valb,best8.)));
Call symput(compress("_parmc"||put(cnt,3.)),
compress(put(valc,best8.)));
Call symput(compress("_parmd"||put(cnt,3.)),
compress(put(vald,best8.)));
call symput("_tot",put(cnt,3.));
run;
%do _i=1 %to &_tot;
%_macrun(_pa=&&_parma&_i,_pb=&&_parmb&_i,_pc=&&_parmc&_i,_pd=&&_parmd&_i);
%end;
%mend _overall;
%_overall;
Of course, you now need to ensure that the multiple run in macro _macrun
produce identifiable output.
Why don't you ask Ron? He's right there at cdc, isn't he?
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Lamias,
Mark (CDC/CCID/OD) (CTR)
Sent: Wednesday, January 24, 2007 2:22 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Macro Variable Problem (or should I say, coder problem)
All,
I am working on a piece of macro code that uses "call execute" to loop
through a dataset and pass parameters to a macro. The macro should then
execute proc sql statements and place the selected variable into a new
macro variable (via a select into statement). Then the new macro
variable should be used throughout the remainder of the macro to be used
in data manipulations, etc.
The problem I am running into is that the macro variable that is created
during the proc sql statement does not seem to change during each call
to the macro. However, the macro variable DOES seems to change if I
just hard-code several calls to the macro statement.
For your reference, I have provided a simplified version of what I am
trying to do (using the sashelp.class for this example).
%macro AgeChange(name);
proc sql noprint;
select age into :MVage
from
sashelp.class
where
name="&name";
quit;
%put &MVage;
%mend;
data work.looptable;
set sashelp.class;
run;
data _null_;
set work.looptable;
call execute('%AgeChange(' || compress(name) || ');' );
run;
If I hard code
% AgeChange(Alfred);
% AgeChange(Alice);
Instead of executing the data _null_ block of code above, I get the
following as expected in the log:
14
13
However, if I run the data _null_ block of code which should be making
the same "%AgeChange()" calls to the macro, I do not get these results.
It appears the macro variables created in the select into statement are
not resolving correctly after each iteration through the looptable. So
my question is: how can I get them to resolve correctly (or at least the
way I'm intending them to) at each iteration?
Thanks for your help.
Mark J. Lamias
|