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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.