BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
malena
Calcite | Level 5

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

catx will work if the target variable is large enough 

 

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

 

PG

View solution in original post

7 REPLIES 7
Reeza
Super User

What did you try?

 

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

 

My suggestion would be CATX().

art297
Opal | Level 21

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

 

malena
Calcite | Level 5
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
art297
Opal | Level 21

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

 

 

Reeza
Super User

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.

 

 

 

Astounding
PROC Star

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.

PGStats
Opal | Level 21

catx will work if the target variable is large enough 

 

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

 

PG

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
  • 7 replies
  • 920 views
  • 2 likes
  • 5 in conversation