Hello,
I am trying to transform a column variable into several dummy variables with one row per ID.
Here is the data I have:
ID, Referral Type
1, Housing
1, Transportation
2, Food
3, Housing
3, Food
4, Transportation
4, Mental Health
Here is the data I want:
ID, Housing, Transportation, Food, Mental Health
1, 1, 1, 0, 0
2, 0, 0, 1, 0
3, 1, 0, 1, 0
4, 0, 1, 0, 1
Any advice would be greatly appreciated! Thanks 🙂
How do you expect to use that resulting data set?
Your use of "dummy variables" makes me think you may want to use this in some sort of regression. In which case why cause yourself work. Most of the regression procedures support CLASS variables which SAS will use the levels to create dummy variables for you. For most purposes the form of data you have is preferred.
Or if you are looking for a report for people to read some thing like this perhaps:
Note use of DATA Step code to provide a usable data set.
data have; infile datalines dsd dlm=' '; input ID Referral :$15.; datalines; 1 Housing 1 Transportation 2 Food 3 Housing 3 Food 4 Transportation 4 "Mental Health" ; proc tabulate data=have; class id referral; table id, referral*n=' ' /misstext='0' ; run;
data have;
infile datalines dsd dlm=' ';
input ID Referral $15.;
var=1;
datalines;
1 Housing
1 Transportation
2 Food
3 Housing
3 Food
4 Transportation
4 Mental Health
;
proc transpose data=have out=temp(drop=_name_);
by id;
id Referral;
var var;
run;
proc stdize data=temp out=want missing=0 reponly;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.