* 05c - If-Then-Else.sas; /* Subsetting IF */ libname y "y:\sas\data"; data temp; set y.employees; if bdate <= "01Jan60"d; run; proc print data=temp(obs=15); var id bdate; run; /* Conditional processing, IF-THEN */ data temp2; set y.employees; if bdate le "01Jan60"d then oldtimer = 1; run; proc freq data=temp2; tables oldtimer; run; data temp2; set y.employees; oldtimer = 0; if bdate le "01Jan60"d then oldtimer = 1; run; proc freq data=temp2; tables oldtimer; run; /* Conditional processing, IF-THEN-ELSE */ data temp2; set y.employees; if bdate le "01Jan60"d then oldtimer = 1; else oldtimer = 0; run; proc freq data=temp2; tables oldtimer; run; /* Chained Conditions, IF-ELSE IF */ data temp2; set y.employess; if bdate le "01Jan60"d then oldtimer = 1; else if bdate gt "01Jan60"d then oldtimer = 0; run; proc freq data=temp2; tables oldtimer; run; /* Serial IF-THEN versus Nested IF-THEN */ data temp3; set y.employees; if salary - salbegin gt 30000 then bigbucks = 3; if salary - salbegin gt 20000 then bigbucks = 2; if salary - salbegin gt 10000 then bigbucks = 1; if salary - salbegin le 10000 then bigbucks = 0; run; proc freq data=temp3; tables bigbucks; run; data temp3; set y.employees; if salary - salbegin gt 30000 then bigbucks = 3; else if salary - salbegin gt 20000 then bigbucks = 2; else if salary - salbegin gt 10000 then bigbucks = 1; else if salary - salbegin le 10000 then bigbucks = 0; run; proc freq data=temp3; tables bigbucks; run;