Hi all,
I have a dataset like this (obviously i have more than 4 rows though),
1 abc
2 def
3 ghi
4 jkl
I want to turn it into
1 abcdefghijkl
I've tried using a put function but for some reason i end up with
abc .
def .
ghi .
jkl .
This is still a string, but just each row is now a paragraph instead, with a weird dot to show the row's end. I would like to remove that and just have the content of the variable from each row to concatenate and become one whole string. Also the data is alphanumeric as it wouldve been A-Z1-100.
If anyone has any idea please help.
I would use CALL CATS, which appends the second parameter (stripped of blanks) to the first variable:
data want;
set have;
length longstring $5000;
retain longstring;
call cats(longstring,string);
run;
s_lassen has the right approach. To get the first id you can simply set a variable with the value and retain it.
data d;
length a 8 b $3;
infile cards;
input a b $;
cards;
1 abc
2 def
3 ghi
4 jkl
run;
data b;
length n1 8 n2 $32760;
set d end=eof;
retain n1 n2;
if _n_ = 1 then n1 = a;
call cats(n2,b);
keep n1 n2;
if eof then output;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.