0
votes

I am trying to create a local macro variable with the %LET statement, the value of which is a macro variable that requires multiple ampersands to resolve. SAS is not resolving the multiple ampersands before assigning the name of the local macro variable.

%macro example;
%do i=1 %to %sysevalf(&max_n);
    %let dg= &&max_&i..;
    {stuff happens here}
%end;
%mend;
%example;

For example, &max_1. resolves to APPLE which I use in the {stuff happens here} portion of the code. However, SAS is giving me the warning "WARNING: Apparent symbolic reference MAX_ not resolved." And the DG macro variable is returning &&max_1 through &&max_17. Calling &DG. at this point will return &&max_1 which will resolve to APPLE on its own, but this will not work with the syntax in the code I'm not showing.

Any idea how to make the macro variable so that &DG. will return APPLE?

2
Add another & in front of it.Reeza

2 Answers

2
votes

(I know this is not an answer but I cannot post formatted code in comments. I will edit/remove this post afterwards).

The code you posted here is not your culprit. If I take it as-is, initialize a couple variables in front and put a %put statement where stuff happens:

%let max_1=APPLE;
%let max_n=1;

%macro example;
%do i=1 %to %sysevalf(&max_n);
    %let dg= &&max_&i..;
    %put &dg;
%end;
%mend;
%example;

You can copy/paste this and run it and it will print 'APPLE' to your log as expected.

There must be something more to what you are trying to do that is causing your issue.

1
votes

Also, the macro variables are not resolved (or not needed to exist in parent or current scope) until macro execution time when the macro is invoked. Thus, the assignment of max_1 and max_n can occur after the macro definition and before the %example.

The behavior you are experiencing could be due to macro quoting you applied to the variables prior to the macro invocation. You can either use %unquote within the macro at callee scope, upon the macro resolution at caller scope, or determine how to process your concepts and inputs with reduced amounts of quoting.

Note: Numerically indexed macro variables are sometimes called 'macro arrays'. macro variables suffixed with symbols are sometimes called 'macro associative arrays' or 'macro objects'