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.

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