Code: -
proc sql noprint;
select distinct 'income' || strip(put(income,8.)) into :income_var separated by ' '
from people;
quit;
data people(rename = (in = income));
set people(rename = (income = in));
length &income_var. 8;
array tmp_arr(*) income:;
do i = 1 to dim(tmp_arr);
if in eq i then tmp_arr(i) = 1;
else tmp_arr(i) = 0;
end;
drop i;
run;
Work: SAS code is dynamic and will work for any number of levels of income variable, because it automatically creates the number of variables according to the number of different levels in the data set of people.
The data step sets the corresponding variable to 1, and the others to 0 according to the value of the income variable.
source
share