Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Create a variable with case when

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-17-2018 10:03 AM
(605 views)

Hello,

I am working with a dataset where the Race Category was input rather oddly.

Essentially, I have 8 binary variables, Race_White, Race_Black, Race_Asian, etc.

For each variable the response is 0 if false or 1 if true.

I need to combine each of these variables into a single race category for analysis.

Essentially creating a variable of Race where 1=White, 2=Black, 3=Asian etc. from the binary variables.

So far I am striking out. it seems to me this should be an if then function but I seem to be missing something

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Will the variables only be populated once? If so you could just do:

data want; set have; select (sum(of race_:)); when 1 then race="White"; when 2 then race=...; ... end; run;

If not then you would need to do each one, and cat the result:

data want; set have; array r{*} race_;; do i=1 to dim(r); if r{i}=1 then race=catx(',',race,vname(r{i}); end; race=tranwrd(race,"race_",""); run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

It's not odd. It's done this way to account for multiple entries, ie someone can flag both White and Black, and **it's also how a regression model requires the variables for analysis -** with the dummy coded values of 0/1. Make sure you need to change it first.

@DanielQuay wrote:

Hello,

I am working with a dataset where the Race Category was input rather oddly.

Essentially, I have 8 binary variables, Race_White, Race_Black, Race_Asian, etc.

For each variable the response is 0 if false or 1 if true.

I need to combine each of these variables into a single race category for analysis.

Essentially creating a variable of Race where 1=White, 2=Black, 3=Asian etc. from the binary variables.

So far I am striking out. it seems to me this should be an if then function but I seem to be missing something

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for the assistance, though I figured out how to do it without using an array.

The issue I was having was a simple thing in my data statement.

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.