Solved
Contributor
Posts: 40

# Combining 460 variables into 1

I have up to 460 variables per person (test results). So I would like to combine all of these into 1 variable.

id result1 result2.... result460

x1 alcohol

x2 alcohol  opioid fentanyl

I tried using the catx function but did not work, not all resuls were combined.

thank you,

malena

Accepted Solutions
Solution
‎03-24-2017 07:53 AM
Posts: 5,628

## Re: Combining 460 variables into 1

[ Edited ]

catx will work if the target variable is large enough

``````length oneVar \$5500;
oneVar = catx(" ", of result:);``````

PG

All Replies
Super User
Posts: 24,028

## Re: Combining 460 variables into 1

What did you try?

Post the code and what happened that makes you think it's incorrect.

My suggestion would be CATX().

Super User
Posts: 8,220

## Re: Combining 460 variables into 1

It would help if you explained what you want to achieve. Combining the data is easy, however it may or may not result in anything that will help you do what you ultimately want to obtain.

Art, CEO, AnalystFinder.com

Contributor
Posts: 40

## Re: Combining 460 variables into 1and them only search this one variable

no attachments. -##
Ultimately i am going to do a text search for specific results names, do don't want to have to search all 460 columns, so want to put all of these into 1 and only do the text search once
Super User
Posts: 8,220

## Re: Combining 460 variables into 1and them only search this one variable

I think that would be easier if you made the file long. e.g.:

```data have;
input (id result1 result2 result460) (\$);
cards;
x1 alcohol . .
x2 alcohol  opioid fentanyl
;
proc transpose data=have out=want (drop=_:);
by id notsorted;
var result1--result460;
run;
```

Art, CEO, AnalystFinder.com

Super User
Posts: 24,028

## Re: Combining 460 variables into 1and them only search this one variable

Have you looked at WHICHC function? It can take an array of values as second argument.

Or a transpose to a long format then you could filter via a single WHERE query.

Super User
Posts: 6,939

## Re: Combining 460 variables into 1

[ Edited ]

Well, you haven't shown what you actually tried.  So here's a guess as to why it didn't work.

The variable you use to hold all 460 values has to be long enough:

length newvar \$ 15000;

Of course, once you realize how long the variable needs to be, you may have second thoughts about combining all 460 values.  There might be a way to get where you need to go, while still leaving the data as 460 separate variables.

Also note, if you are going to search for a particular string within, you might be making your life harder.  That string might appear multiple times, and finding all of them would become more difficult.

Solution
‎03-24-2017 07:53 AM
Posts: 5,628

## Re: Combining 460 variables into 1

[ Edited ]

catx will work if the target variable is large enough

``````length oneVar \$5500;
oneVar = catx(" ", of result:);``````

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 7 replies
• 217 views
• 2 likes
• 5 in conversation