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

Hi,

I would like to concatenate across columns containing a string of single characters to obtain a new column containing the letters arranged in alphabetic order. This will allow me to identify all the people with the same combination. 

 

I would really appreciate any help! Thank you!

 

data have:

id d1 d2 d3 d4 

1 A B C D 

2 B D A C

3 D A B C

4 E B F D

etc

 

data want:

id concat

1 ABCD

2 ABCD

3 ABCD

4 BDEF

etc

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Use CALL SORTC to sort the variables then concatename them:

 

data want;

 set have;

      array dx d1-d4;

      call sortc(of dx(*));

      concat=cat(dx(*));   /* OR concat=compres(d1||d2||d3||d4);   OR concat=cat(d1,d2,d3,d4) */

      drop d1-d4;

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

CALL SORTC along with CATT

 

Please review the documentation if you need to review usage. 

 

call sortc(of d1-d4);
x = catt(of d1-d4);

In addition, please consider posting data as a data step, you're close but missing the input statement in your sample.

It helps...since that means I might take a few minutes to actually test this rather than just assume it works and leave the testing to you. 

So really, it's in your best interest to post data as a data step. 

 

Shmuel
Garnet | Level 18

Use CALL SORTC to sort the variables then concatename them:

 

data want;

 set have;

      array dx d1-d4;

      call sortc(of dx(*));

      concat=cat(dx(*));   /* OR concat=compres(d1||d2||d3||d4);   OR concat=cat(d1,d2,d3,d4) */

      drop d1-d4;

run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 1595 views
  • 2 likes
  • 3 in conversation