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!
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?
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.
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.
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.
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).
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?
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.
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.
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.