ID NAME
1 FirstName
1 LastName
1 ABC
How to combine this into single variable
Output :-FirstName LastName ABC
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;
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;
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
I don't understand this. Do you want the values in a single variable or multiple variables.
Please be more specific.
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.