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

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:

ObsBarrier1Barrier2Barrier3Barrier4Barrier5Barrier6Barrier7
1ChildFundingTitle IV-E
2FundingCourtsTeam
3PolicyTeamOther
4ChildCourts
5FundingPolicy
6ChildCourtsTitle IV-EOther

Desired new variable:

ObsBarriers
1Child, Funding, Title IV-E
2Funding, Courts, Team
3Policy, Team, Other
4Child, Courts
5Funding, Policy
6Child, Courts, Title IV-E, Other
1 ACCEPTED SOLUTION
3 REPLIES 3
TashaLChapman
Calcite | Level 5

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! Smiley Happy

(That's 2 for 2 today, Reeza.)

ballardw
Super User

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 1111 views
  • 3 likes
  • 3 in conversation