Go Back   Rhinocerus > Newsgroup > Newsgroup comp.soft-sys.sas

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2007, 07:38 PM
toby dunn
Guest
 
Posts: n/a
Default Re: Macro Variable Problem (or should I say, coder problem)

Paul ,

See Data _Null_ 's post or read my paper over Data Step Interfaces to the
Macro Facility. Both cover the problem and how to solve it.



Toby Dunn

To sensible men, every day is a day of reckoning. ~John W. Gardner

The important thing is this: To be able at any moment to sacrifice that
which we are for what we could become. ~Charles DuBois

Don't get your knickers in a knot. Nothing is solved and it just makes you
walk funny. ~Kathryn Carpenter






From: "Paul A. Thompson" <paul@WUBIOS.WUSTL.EDU>
Reply-To: "Paul A. Thompson" <paul@WUBIOS.WUSTL.EDU>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Macro Variable Problem (or should I say, coder problem)
Date: Wed, 24 Jan 2007 14:33:47 -0600

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=&&_pa rmc&_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

__________________________________________________ _______________
Laugh, share and connect with Windows Live Messenger
http://clk.atdmt.com/MSN/go/msnnkwme...urce=hmtagline
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Problem with Macro resolution Don Henderson Newsgroup comp.soft-sys.sas 0 04-10-2008 01:41 AM
Re: Macro variable for Data set name is being "parsed", David L Cassell Newsgroup comp.soft-sys.sas 0 06-28-2007 12:16 AM
Re: MAcro Design was (Re: Macro quoting essentials) Ian Whitlock Newsgroup comp.soft-sys.sas 3 12-11-2005 11:18 PM
Re: surveyselect question Zack, Matthew M. Newsgroup comp.soft-sys.sas 1 01-18-2005 06:26 PM
Re: macro variable contains invalid chars Fehd, Ronald J. Newsgroup comp.soft-sys.sas 1 10-25-2004 01:38 PM



All times are GMT. The time now is 01:44 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.