- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;