Using CALL SYMPUT with a macro name that contains a variable

Reply
N/A
Posts: 1

Using CALL SYMPUT with a macro name that contains a variable

Towards the top of my program, I have:

%LOCAL ix;
%LET ix = 1;
%DO ix = 1 %to 4;
%LOCAL corra_&ix;
%LET corra_&ix = 9999;
...
%END;

This compiles and runs without problems. I call %PUT _USER_ and I see all my variables defined among the others I have. (I've initialised them to 9999 because I can see later if any operations have been carried out later)

My problem is coming later on:

%do i = 1 %to 4;
...
CALL SYMPUT(%quote('CORRA_&i'), trim(left(put(DEPEN&i,5.3))));
...
%end;

When the program runs, I want the result to be
CALL SYMPUT('CORRA_1', trim(left(...)));
CALL SYMPUT('CORRA_2', trim(left(...)));
CALL SYMPUT('CORRA_3', trim(left(...)));
CALL SYMPUT('CORRA_4', trim(left(...)));

But I cannot for the life of me work out how to correctly resolve this. I'm either receiving notes in my log that my variable is uninitialised, or that the 'Apparent Symbolic Reference is not resolved'. In any case, when I use %PUT _USER_; later on, the variables are still equal to 9999.

What should I put in place of the bold text to make this work?

Thanks in advance.
SAS Super FREQ
Posts: 8,645

Re: Using CALL SYMPUT with a macro name that contains a variable

Hi,
Run this test. [pre]
%let i = 5;
data _null_;
depen5 = 64.3;
CALL SYMPUT("CORRA_&i", trim(left(put(DEPEN&i,5.3))));
run;

%put _user_;
[/pre]
Unless you need the single quotes for something else that was going on in the program, you can replace the %quote function with double quotes and the resolution should be OK.
cynthia
Post a Question
Discussion Stats
  • 1 reply
  • 253 views
  • 0 likes
  • 2 in conversation