BookmarkSubscribeRSS Feed
Lokesh4
Calcite | Level 5

Team could you please help me out with the below problem

Eg: I have the below table

Company    ID     DESIGNATION 

ABC            1       Employee

ABC            1      Supervisor

ABC            2      Manager

I wanted  the data to be concatenated as below in one variable, the new_var should have id concatenated with designation, can you please help me out

Company    ID     DESIGNATION   New_var

ABC            1       Employee          1-Employee, 1-Supervisor, 2-Manager

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

@Lokesh4 

Welcome to the SAS community!

 

Why on earth did you post a new question after an unrelated discussion?

 

As importantly, did you even read what the discussion is about?

It is about posting your sample data in the correct format, which you -very ironically- have not done!

 

Moving the question from here to the programming forum.

 

PaigeMiller
Diamond | Level 26

@Lokesh4 wrote:

Team could you please help me out with the below problem

Eg: I have the below table

Company    ID     DESIGNATION 

ABC            1       Employee

ABC            1      Supervisor

ABC            2      Manager

I wanted  the data to be concatenated as below in one variable, the new_var should have id concatenated with designation, can you please help me out

Company    ID     DESIGNATION   New_var

ABC            1       Employee          1-Employee, 1-Supervisor, 2-Manager


The output you want is not consistent with the Input. ID 1 has only two records in the input, yet in the output it seems as if you are concatenating three records for ID 1. Could you please clarify this? Also, where does DESIGNATION come from?

 

Also, concatenating long data sets into wide data as you are asking to do is rarely necessary and rarely a good thing to do. What will you be doing with this variable NEW_VAR?

--
Paige Miller
CarlosSpranger
Obsidian | Level 7

Hello @Lokesh4,

 

Whatever your need is, here you have it:

data test;
input Company $ ID Designation $;
Datalines;
ABC 1 Employee
ABC 1 Supervisor
ABC 2 Manager
run;

Data want;
set test;
new_var= CATX('-',ID,Designation);
run;

/*The result below*/

result.PNG

 

 

CSB
Kurt_Bremser
Super User

If a company has 3000 employees or more, you will overflow the maximum length of character variables, unless your rule for concatenating is different than what it seems to be in your example.

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
  • 4 replies
  • 547 views
  • 1 like
  • 5 in conversation