Hi Assuming the input data is sorted by var_1, then the following code should do what you want: data want; set have; by Var_1; if first.var_1 = 1 then do; retain checkForA; checkForA = 1; end; if checkForA = 1 and var_2 = "A" then do; var_3_sas = 1; checkForA = 0; end; var_3_sas = coalesce(var_3_sas, 0); run;
... View more