DATA Step, Macro, Functions and more

Need help combining Variables

Reply
Occasional Contributor
Posts: 6

Need help combining Variables

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!

Trusted Advisor
Posts: 1,934

Re: Need help combining Variables

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?

Occasional Contributor
Posts: 6

Re: Need help combining Variables

Posted in reply to PaigeMiller

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.

Super User
Posts: 5,518

Re: Need help combining Variables

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.

Occasional Contributor
Posts: 6

Re: Need help combining Variables

Posted in reply to Astounding

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.

Trusted Advisor
Posts: 1,934

Re: Need help combining Variables

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

Super User
Posts: 5,518

Re: Need help combining Variables

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?

Super User
Posts: 5,518

Re: Need help combining Variables

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.

Super User
Posts: 11,343

Re: Need help combining Variables

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.

Ask a Question
Discussion stats
  • 8 replies
  • 355 views
  • 3 likes
  • 4 in conversation