BookmarkSubscribeRSS Feed
animesh123
Obsidian | Level 7

ID    NAME
1    FirstName

1    LastName

1    ABC

How to combine this into single variable

Output :-FirstName LastName ABC

 

 

5 REPLIES 5
Adriaan_Gouws
Obsidian | Level 7

Good day

 

Please give the below a go.

DATA WANT;
  SET HAVE;
  BY ID;
  LENGTH COMBINED $200;
  RETAIN COMBINED;
  COMBINED=IFC(FIRST.ID,NAME,CATX('-',COMBINED,NAME));
  IF LAST.ID THEN OUTPUT;
RUN;
PeterClemmensen
Tourmaline | Level 20
data have;
input ID NAME :$10.;
datalines;
1 FirstName 
1 LastName  
1 ABC       
;

data want;
   do until (last.id);
      set have;
      by id;
      length comb $ 200;
      comb = catx(' ', comb, name);
   end;
run;
animesh123
Obsidian | Level 7

Thanks. I have tried executing the same but the output is different then i have expected 

Output will be :-

e.g:

1  FirstName LastName ABC

1 Daniel    Riccardo   ABC

 

PeterClemmensen
Tourmaline | Level 20

I don't understand this. Do you want the values in a single variable or multiple variables. 

 

Please be more specific.

Tom
Super User Tom
Super User

@animesh123 wrote:

Thanks. I have tried executing the same but the output is different then i have expected 

Output will be :-

e.g:

1  FirstName LastName ABC

1 Daniel    Riccardo   ABC

 


That output does not look like it could have been generated from the input you provided in your question.  There was no Daniel in your original data for example.

 

Provide a more complete example input.  Provide the output that you expect from that input.  Provide both as actual working data steps that create SAS datasets so there are no questions about the names, types, lengths, etc of the variables you have and the variables you want.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1170 views
  • 1 like
  • 4 in conversation