Date: Fri, 21 Dec 2001 11:47:43 -0500
Reply-To: "David L. Ward" <dward@SASHELP.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Ward" <dward@SASHELP.COM>
Subject: Re: Conditional running of a Macro
In-Reply-To: <1F954755A8C1D511A5E2000255F00502CC560E@goaexsr2.hro.af.com>
Content-Type: multipart/signed;
;
protocol="application/x-pkcs7-signature"; micalg=SHA1
Ben,
This is a case where you need to be careful about macro variable scope.
By default, macro variables used inside of a macro are LOCAL in scope,
so they persist only during the execution of your macro. To carry the
variable FLAG from the data step and call symput in %step1, just declare
flag as global:
global flag;
Put this somewhere in the macro %step1
HTH
David Ward
SASHelp.com
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of
Krone, Ben --- Manager - Operations Systems --- GO
Sent: Friday, December 21, 2001 11:24 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Conditional running of a Macro
Happy Holidays!
I am a macro novice and could use a little help on conditional running
of a macro. Basically I want to check a parameter passed to the job and
determine whether or not to further process based on the results of that
check. Here is an example of the code I am running:
%macro main;
%step1;
%if &flag eq 'Y' %then %do;
%out1;
%end;
%else %do;
%out2;
%end;
%mend main;
%step1;
data _null_;
parm = sysparm();
call symput('parm',"'"||trim(parm)||"'");
run;
proc sql;
connect to db2 (ssid = dsn);
execute (set current degree = 'ANY') by db2;
create table flag as select * from connection to db2
(select flag
from db2table
where col1 = &parm
for fetch only);
disconnect from db2;
quit;
data _null_;
set flag;
call symput('flag',"'"||trim(flag)||"'");
run;
%mend step1;
%macro out1;
< further processing >
%mend out1;
%macro out2;
data _null_;
put 'Invalid parameter for this job';
run;
%mend out2;
%main;
When I run this, I get the following error:
WARNING: Apparent symbolic reference FLAG not resolved.
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition was:
&flag eq 'Y'
ERROR: The macro MAIN will stop executing.
I am certain it has to do with the scope of the macro variable from the
CALL SYMPUT, but I am not sure what an alternative would be.
Any help would be greatly appreciated.
Thanks
Ben
******************************************************************
This message contains information that is confidential
and proprietary to American Freightways Inc.
or its affiliates. It is intended only for the recipient
named and for the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************************
smime.p7s [application/x-pkcs7-signature]