Hello
What is the reason for error here?
This code has no special meaning but I want to learn it
The error is:
WARNING: Apparent symbolic reference I not resolved.
NOTE: Line generated by the macro variable "I".
32 &YYMM&
_
22
WARNING: Apparent symbolic reference YYMM not resolved.
WARNING: Apparent symbolic reference I not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.
%let YYMM1=2005;
%let YYMM2=1809;
%let YYMM3=1912;
%let YYMM4=1812;
data c;
do i = 1 to 4;
vec =&&YYMM&i;
output;
end;
run;
The variable i is a data-step variable, but you are using it as a macro-variable. Try something like
vec = resolve(cats('&YYMM', i));
instead.
@Ronein wrote:
Hello
What is the reason for error here?
This code has no special meaning but I want to learn it
The error is:
WARNING: Apparent symbolic reference I not resolved.
NOTE: Line generated by the macro variable "I".
32 &YYMM&
_
22
WARNING: Apparent symbolic reference YYMM not resolved.
WARNING: Apparent symbolic reference I not resolved.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, INPUT, PUT.%let YYMM1=2005; %let YYMM2=1809; %let YYMM3=1912; %let YYMM4=1812; data c; do i = 1 to 4; vec =&&YYMM&i; output; end; run;
You really need to start now to make use of the documentation, in this case, the chapter about Data Step Interfaces of the macro facility.
There you will find the SYMGET Function , which is the tool of choice to read the value of a macro variable dynamically in a data step:
%let YYMM1=2005; %let YYMM2=1809; %let YYMM3=1912; %let YYMM4=1812; data c; do i = 1 to 4; vec = symget(cats('YYMM',i)); output; end; run;
An alternative is to code generate four sets of assignment, followed by output statements . In this scenario the looping would be a macro %DO
loop and necessarily be inside a macro definition.
%macro learning;
%let YYMM1=2005;
%let YYMM2=1809;
%let YYMM3=1912;
%let YYMM4=1812;
data c;
%DO i = 1 %to 4;
vec =&&YYMM&i;
output;
%END;
run;
%mend;
options mprint;
%learning
Log
15 %learning
MPRINT(LEARNING): data c;
MPRINT(LEARNING): vec =2005;
MPRINT(LEARNING): output;
MPRINT(LEARNING): vec =1809;
MPRINT(LEARNING): output;
MPRINT(LEARNING): vec =1912;
MPRINT(LEARNING): output;
MPRINT(LEARNING): vec =1812;
MPRINT(LEARNING): output;
MPRINT(LEARNING): run;
Suppose you manage a race car pit stop. The car comes in, what do you do ?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.