Hi folks,
Probably a common problem, and I'm just blanking on a solution that doesn't require 5,040 lines of code...
I have seven variables, of which any number of them can be populated or missing. In any combination. And I'd like to concatenate them into a single variables that displays the populated values as a list separated by commas. But obviously I don't want extraneous commas, so I only want the new variable to include non-missing values. Any thoughts on how to do this?
Original data:
Obs | Barrier1 | Barrier2 | Barrier3 | Barrier4 | Barrier5 | Barrier6 | Barrier7 |
---|---|---|---|---|---|---|---|
1 | Child | Funding | Title IV-E | ||||
2 | Funding | Courts | Team | ||||
3 | Policy | Team | Other | ||||
4 | Child | Courts | |||||
5 | Funding | Policy | |||||
6 | Child | Courts | Title IV-E | Other |
Desired new variable:
Obs | Barriers |
---|---|
1 | Child, Funding, Title IV-E |
2 | Funding, Courts, Team |
3 | Policy, Team, Other |
4 | Child, Courts |
5 | Funding, Policy |
6 | Child, Courts, Title IV-E, Other |
call catx function
call catx function
Oh, duh. It really is a Friday isn't it... where is my brain? I'm so used to using the long-hand version with the concatenation operator I completely forgot about the catx function. Thanks!
(That's 2 for 2 today, Reeza.)
I would start with CATX function in a data step
data want;
set have;
length combinedBarriers $ <big enough integer to store longest combination>;
combinedbarriers = catx(',' of Barrier1-Barrier7);
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: