Search code examples
if-statementsasfiltering

Can anybody please explain how sas is solving this code?


One quick question: why does sas solve the following code

data prova_2;
input id_2 $ age_2;
datalines;
zz 22
zz 22
zz 22
zz 23
xx 22
xx 24
aa 25
;
run;

data prova_2;
set prova_2;
if id_2="zz" then do; if age_2=23; end;
run;

by outputting the following table?

enter image description here

I would instead expect it to output just one single line, ie, line 1, the one with id_2="zz" and age_2=23. Any idea?

Thanks in advance!


Solution

  • You are running the subsetting IF only on SOME of the observations.

    So all observations where ID_2 is not zz will also continue to the end of the data step and be written out.

    So you are doing the equivalent of

    if (id_2='zz') and (age_2 ne 23) then DELETE;