BookmarkSubscribeRSS Feed
AlexMoreton
Obsidian | Level 7

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.

2 REPLIES 2
s_lassen
Meteorite | Level 14

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;
foobarbaz
Obsidian | Level 7

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;
Regards,
Cameron | Selerity

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
  • 2 replies
  • 1629 views
  • 1 like
  • 3 in conversation