I have a SAS table that has the if condition embedded in the condition1 column of that table. To be more explicit, I created a test dataset:
data test;
infile datalines delimiter=',';
input x1 x2 flag $ condition1 $ value_cond1_true $ value_cond1_false $ ;
datalines;
1,5, ,x1>x2,A,B
6,5, ,x2>x1,D,A
3,2, , ,C,D
;
run;
I am wondering if it possible to create a code that can directly output in the SAS code the if statement instead of creating a single macro-variable for each observation (&cond1_1, &cond1_2, ... &cond1_n).
Here is what I would want to do (I know it is not possible to use call symput in that case):
data final;
set test;
/* For each observation */
do i=1 to _n_;
/* Creating macro-variables for the if condition */
call symput("cond1",CONDITION1);
call symput("value_cond1_true",VALUE_COND1_TRUE);
call symput("value_cond1_false",VALUE_COND1_FALSE);
/* If the cond1 macro-variable is not empty then do */
if %sysevalf(%superq(cond1)=, boolean) = 0 then do;
if &cond1. then flag = &value_cond1_true.;
else flag = &value_cond1_false.;
end;
/* If the cond1 macro-variable is empty then */
else flag = "X";
end;
run;
Aucun commentaire:
Enregistrer un commentaire