Here is the code I'm trying to execute but keep hitting error.
&FLG is a variable imported from a different table
¯o1 and ¯o2 are variables I'm trying to store values based on the condition rules (condition1-4).
<The original code with success>
data want;
set table;
where condition;
if condition1 then do;
¯o1.
end;
else do;
¯o2.
end;
run;
<The edited code with failure>
data want;
set table;
where condition;
if &FLG. eq Y then do;
if condition1 then ¯o1.;
if condition2 then ¯o2.;
end;
if &FLG. eq N then do;
if condition3 then ¯o1.;
if condition4 then ¯o2.;
end;
run;
It would be a great help if you can advise which part I'm missing and how to fix the code to run successfully.
In data step code, you compare variables or values. Character values have to be enclosed in quotes. So, when your %flg macro returns either a Y or N, the data step code has to be
if "%FLG" eq "Y" then do;
In data step code, you compare variables or values. Character values have to be enclosed in quotes. So, when your %flg macro returns either a Y or N, the data step code has to be
if "%FLG" eq "Y" then 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.