/***************************************************************** 25 JUL 96 -- sas.help@umich.edu This code first creates a data set called TEST, containing values for race (1 to 7) and for zip (0 to 6). The second data step creates dummy variables for race and zip, so if race=1 then the dummy variable race1=1, otherwise race1=0...if race=2 then race2=1, otherwise race2=0...etc. The same applies to zip, if zip=0 then zip0=1, otherwise zip0=0... etc. This same code could be accomplished by doing the third data step in long hand. However, with many variables, this can involve a lot of coding! ******************************************************************/ data test; do race=1 to 7; do zip=0 to 6; output; end; end; run; proc print; title 'printout of original data set'; run; /* below is the easy way to create the dummy variables */ data test2; set test; array r(7) race1-race7; array z(7) zip0-zip6; do i=1 to 7; r(i)=(race=i); end; do j=1 to 7; z(j)=(zip=j-1); end; drop i j; output; run; proc print data=test2; title 'printout with easy dummy variables'; run; /* below is the hard way to do dummy variables */ data test3; set test; if race=1 then race1=1; else race1=0; if race=2 then race2=1; else race2=0; if race=3 then race3=1; else race3=0; if race=4 then race4=1; else race4=0; if race=5 then race5=1; else race5=0; if race=6 then race6=1; else race6=0; if race=7 then race7=1; else race7=0; if zip=0 then zip0=1; else zip0=0; if zip=1 then zip1=1; else zip1=0; if zip=2 then zip2=1; else zip2=0; if zip=3 then zip3=1; else zip3=0; if zip=4 then zip4=1; else zip4=0; if zip=5 then zip5=1; else zip5=0; if zip=6 then zip6=1; else zip6=0; run; proc print data=test3; title 'printout with hard dummy variables'; run;