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
catx will work if the target variable is large enough
length oneVar $5500;
oneVar = catx(" ", of result:);
What did you try?
Post the code and what happened that makes you think it's incorrect.
My suggestion would be CATX().
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
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
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.
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.
catx will work if the target variable is large enough
length oneVar $5500;
oneVar = catx(" ", of result:);
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.
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.