BookmarkSubscribeRSS Feed
love_epi
Calcite | Level 5

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 🙂

2 REPLIES 2
ballardw
Super User

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;

 

Ksharp
Super User
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;

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 588 views
  • 1 like
  • 3 in conversation