DATA Step, Macro, Functions and more

Double ampersands in a macro.

Reply
N/A
Posts: 0

Double ampersands in a macro.

I have this macro in the beginning of my program:
%macro m1;
%do i=1 %to 10;
%let row&i=&i;
%end;
%mend;
%m1;

With %put &&row&i inside the macro I have checked that the values of row1 to row10 are from 1 to 10.

In my main program I have an expression

r&&row&k.col(n)=p; (a dot between k and c)

&k is a macro variable ranging from 1 to 10. n is a number from 1 to 5.
I have arrays r1col(5), r2col(5), ... , r10col(5) declared.

I expected to get r1col(n)=p, r2col(n)=p, ... and so on.

But I get the error message: Apparent symbolic reference ROW1COL not resolved.

The same for ROW2COL, and so on.

What have I done wrong?
Respected Advisor
Posts: 4,173

Re: Double ampersands in a macro.

Posted in reply to deleted_user
You have two iterations until the macro var gets resolved. For every iteration a dot is consumed.
You need 2 dots.

%let row1=1;
%let k=1;

%put r&&row&k..com(n)=p;

HTH
Patrick
N/A
Posts: 0

Re: Double ampersands in a macro.

After adding the dot i get the warning(s): Apparent symbolic reference ROW1 not resolved.

Error message concerning r&row1.col: Statement is not valid or it is used out of proper order.
Super Contributor
Posts: 359

Re: Double ampersands in a macro.

Posted in reply to deleted_user
Check to make sure &row1 is global. It looks like a local variable to you macro.
You would need to have %global row&i ; in your macro.
Super Contributor
Super Contributor
Posts: 3,174

Re: Double ampersands in a macro.

We're back to the MACRO VARIABLE SCOPING topic, which came up in a prior post/thread.

Your macro creates a macro variable, which by default is LOCAL, however your SAS program attempts to reference a macro variable, so now your macro variables must be declared as GLOBAL type.

Scott Barry
SBBWorks, Inc.

SAS Macro Language: Reference, Scopes of Macro Variables
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002047080.htm


SAS Macro Language: Reference, Introduction to Macro Variables
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a002293823.htm
Super Contributor
Posts: 359

Re: Double ampersands in a macro.

We need a list of FPQ Frequently posted questions.
Ask a Question
Discussion stats
  • 5 replies
  • 158 views
  • 0 likes
  • 4 in conversation