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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1393 views
  • 3 likes
  • 3 in conversation