Date: Fri, 11 Mar 2005 11:19:07 -0500
Reply-To: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Subject: Re: Difficult problem %Macro parameters - local - global
alain.follet@sham.fr wrote:
> Hello everybody,
>
> I have a question. I'm knowing Sas since many time and I would like to
> adresss you a question. Is there a way to instanciate parameters in a
> macro with another macro without to declare the parameters as global
> macro variables.
>
> I try to explain with a very simple example:
>
> %macro comp(Param);
> %let x=5;
> %let y=8;
> %let z=9;
> /* computed values x, y ,z ...*/
> %mend;
>
> %macro check;
> %comp(param);
> /* How to have here the value of x et y without to declare x et y as
> global macro variables in macro comp ? */
> %mend;
>
> The only way I found is to declare x,y and z as local macro variable
> in check. But this solution is bad as I have dynamic number of
> variables in comp. Is there a solution as like this :
>
> %macro check;
> %let x=%comp(param)[x];
> %let y=%comp(param)[y];
> %let y=%comp(param)[z];
> %mend;
Hi,
Maybe all you need is to make an extra named (thus optional) parameter for
macro %comp, so that you just pass the name of the macro variable whose
value you want to get from the macro like below.
Or you can do: (1) move the %check macro into the %comp; (2) add a debug=
parameter to %comp; and (3)when debug is set then execute the check part of
macro code. HTH.
Cheers,
Chang
%macro comp(param, return=);
%local x y z;
%let x = 5;
%let y = 8;
%let z = 9;
%* do something *;
%if "%trim(&return)"^="" %then %do;
%*;&&&return..
%end;
%mend;
%macro check;
%put x = %comp(param, return=x);
%put y = %comp(param, return=y);
%mend;
%check
/* on log
x = 5
y = 8
*/
/* an alternative way */
%macro comp(param, debug=no);
%local x y z;
%let x = 5;
%let y = 8;
%let z = 9;
%* do something *;
%if "%upcase(&debug.)" = "YES" %then %do;
%put x=&x.;
%put y=&y.;
%end;
%mend;
%comp(param, debug=YES)
/* on log
x = 5
y = 8
*/