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!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.