Dummy variables in SAS
sas
Solution
A somewhat more flexible way to do it is with arrays.
data people;
set people;
array incomes income1-income4;
do _t = 1 to dim(incomes);
if income=_t then income[_t] = 1;
else if not missing(income) then income[_t]=0;
else income[_t]=.;
end;
run;
Problem
Suppose we have some data set `people` which has a categorical variable `income` with 4 levels (1,2,3,4). How would we code this in SAS? Would it be: ``` data people; set people; if income=1 then income1=1; else if income=2 then income2=1 else if income =3 then income3=1; run; ``` In other words, this would create three dummy variable for the four levels. Is this right?