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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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