That is not easy to do. For your simple example you could do:
data want ;
set have ;
if cats('Answer=',answer) = condition then ....
But that will not generalize to situations where CONDITION references the values of other variables. You might be able to generate code from a set of unique values of CONDITION.
Sample data:
data have ;
infile cards dsd truncover ;
input Question $ Answer Condition :$30. Expected $ ;
cards;
Q1,1,Answer=1,"Correct"
Q2,2,Answer=1,"Wrong"
Q3,3,Answer=4,"Wrong"
;;;;
Generate code using unique values of CONDITION.
filename code temp ;
data _null_;
set have end=eof ;
by condition ;
file code ;
if _n_=1 then put 'SELECT ;' ;
if first.condition then put ' WHEN (' CONDITION= :$quote. ' AND (' condition ')) RESULT="CORRECT" ;' ;
if eof then put ' OTHERWISE RESULT="WRONG";'
/ 'END;'
;
run;
Use the generated code in a data step.
data want ;
set have ;
%inc code / source2;
run;
Sample Log records.;
252 data want ;
253 set have ;
254 %inc code / source2;
255 +SELECT ;
256 + WHEN (Condition="Answer=1" AND (Answer=1 )) RESULT="CORRECT" ;
257 + WHEN (Condition="Answer=4" AND (Answer=4 )) RESULT="CORRECT" ;
258 + OTHERWISE RESULT="WRONG";
259 +END;
NOTE: %INCLUDE (level 1) ending.
260 run;