Requirement here is to have a global variable (var1) with a default value (1) that may be manipulated (conditional new value = Y) under 1st datastep (data1) and then to use it under 2nd datastep (_null_) to perform some other action conditionally.
Problem is, under the _null_dataset though var1 is carrying correct value (Y) from data1, it's not satisfying the IF-condition, rather going to ELSE-part.
Here is the code:
%global var1;
%let var1 = 1;
data data1;
var2 = 3;
if var2 = 3 then do;
%let var1 = Y;
end;
run;
proc print data=data1;
run;
%put &var1;
data _null_;
varz= symget('var1');
file OUTF;
put @1 'start';
if varz = Y then do;
put @1 'yes';
end;
else do;
put @1 'no';
end;
run;
My expectation is that it should print "yes" from IF-part, not the "no" from ELSE-part.
%LET is a declaration statement and can't be used in a data step as you did it.
Instead you can assign a new value to a macro variable by:
IF ..condition.. then
call symput('VAR1' , 'Y');
on next step you are using call symget which is the right thing to do;
%LET is a declaration statement and can't be used in a data step as you did it.
Instead you can assign a new value to a macro variable by:
IF ..condition.. then
call symput('VAR1' , 'Y');
on next step you are using call symget which is the right thing to do;
@Shmuel Thanks much!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.