DATA Step, Macro, Functions and more

Print macro variable name and value in log via &=mvar

Reply
Super Contributor
Posts: 376

Print macro variable name and value in log via &=mvar

Hi,

put me on to this new feature in SAS 9.3 via a LinkedIn post.

From the 9.3 SAS doc (see Tip for the %PUT statement):

%let x=1;

%put &=x;

However, can anyone (a little birdie perhaps?) say why this doesn't work?

%let y1=2;

%let i=1;

%put Y&i=&&y&i;  * works ;

%put &=y1;  * works ;

%put &=y&i;  * does not work ;

or my more realistic example (from a macro I'm writing):

%let z1=A;

%let z2=B;

%let z3=C;

%macro test;

  %do i=1 %to 3;

    %put Z&i=&&z&i;  * works ;

    %put &=z&i;  * does not work ;

  %end;

%mend;

%test;

Otherwise, consider this a minor bug report and/or enhancement request.

Frequent Contributor
Posts: 85

Re: Print macro variable name and value in log via &=mvar

I think its a "feature".

The doco says: "If you place an equal sign between the ampersand and the macro variable name of a ** direct ** macro variable reference, the macro variable's name displays in the log along with the macro variable's value.

It would be good to be able to an indirect reference though.

Trusted Advisor
Posts: 1,247

Re: Print macro variable name and value in log via &=mvar

Hi Scott & Jerry,

Yes it does appear to be a feature for only "direct" macros. Thought I'd reference the documentation page as well (look for the Tip), http://support.sas.com/documentation/cdl/en/mcrolref/64754/HTML/default/viewer.htm#n189qvy83pmkt6n1b...

Cheers,

Michelle

Ask a Question
Discussion stats
  • 2 replies
  • 276 views
  • 0 likes
  • 3 in conversation