BookmarkSubscribeRSS Feed
WillS_
Calcite | Level 5

Hello,

I am trying to combine multiple 0/1 column variables in to one general column variable. Example: Multiple column data for race such as White, Black, etc. and they are all 0/1. What would be the best way to change them into a single column data variable? Any help is much appreciated!

8 REPLIES 8
PaigeMiller
Diamond | Level 26

It's really hard to understand what you want.

For example, do you want the 0s and 1s in variable White to be combined with the 0s and 1s in Black combined with the 0s and 1s in Hispanic etc.?

What should the output variable look like in this case? Concatenation of zeros and ones? An integer representing the category?

--
Paige Miller
WillS_
Calcite | Level 5

I have changed the variables such as 0/1 variables in each column the 1 = a different number ex. 2 for black column and 3 for Asian column.

Astounding
PROC Star

After that sort of a change, this might do the trick:

race = max(white, black, hispanic, asian, other);

But the cautions about inspecting and understanding what is in your data still apply.

Good luck.

WillS_
Calcite | Level 5

Astounding thank you for getting back to me!

To answer your previous question: There does seem to be missing data in some of the variables. There are no multiple answers for multiple variables.

The max(var) did not work.

PaigeMiller
Diamond | Level 26

Hey, WillS

I'm still not really clear on what your data looks like now, and what you want it to look like when you are done.

I note that all of your explanations have great brevity, but that's not really what's needed here. We need details, we need an actual example or two (not words, but actual examples of part of the data set that you are working with).

--
Paige Miller
Astounding
PROC Star

Well, show us what happened.  What did you code using the MAX function?  Did you get an error, a warning, or just an incorrect result?

Astounding
PROC Star

The best way is to thoroughly examine what is in your data first.  Here are some questions to get started.

1. Is there always an answer to every question, or are there some blanks in addition to the 0/1 values?

2. Does Race have an "other" question?  If so, does it have an open-ended explanation?  How would you like to handle that?

3. Does anyone check multiple answers, such as both "Black" and "White"?

The "best way" could easily change, depending on your answers to these questions.

Good luck.

ballardw
Super User

And a long shot response: if this data originated in some survey software, possibly other sources, examine the export options and consider re-exporting. Some software will allow output of multiple dichotomous variables for choices or a single code. Like I say, long shot.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 1129 views
  • 3 likes
  • 4 in conversation