I want to create something in SAS that works like an Excel lookup function. Basically, I set the values for macro variables var1
, var2
, ... and I want to find their index number according to the ref
table. But I get the following messages in the data step.
NOTE: Variable A is uninitialized.
NOTE: Variable B is uninitialized.
NOTE: Variable NULL is uninitialized.
When I print the variables &num1
,&num2
, I get nothing. Here is my code.
data ref;
input index varname $;
datalines;
0 NULL
1 A
2 B
3 C
;
run;
%let var1=A;
%let var2=B;
%let var3=NULL;
data temp;
set ref;
if varname=&var1 then call symput('num1',trim(left(index)));
if varname=&var2 then call symput('num2',trim(left(index)));
if varname=&var3 then call symput('num3',trim(left(index)));
run;
%put &num1;
%put &num2;
%put &num3;
I can get the correct values for &num1
,&num2
,.. if I type varname='A'
in the if-then
statement. And if I subsequently change the statement back to varname=&var1
, I can still get the required output. But why is it so? I don't want to input the actual string value and then change it back to macro variable to get the result everytime.