Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Concat

Status
Not open for further replies.

nickdel

Programmer
May 11, 2006
367
GB
Hi, lets say i have the following dataset...

Code:
data test1;
input var1 $;

datalines;
a 
b 
c
e 
f
;
run;

and i want to concatenate var1 into one big string i.e. abce...
I've tried this but it doesn't seem to work and I really cant figure out why!

Code:
data test2;
	set Test1;
	retain mstr;

	if _n_ = 1 then mstr = var1;
	else
		mstr = mstr||var1;
run;

All suggestions welcome!

Thanks

Nick
 
Actually got this working...

Code:
data test2;
    set Test1;
    retain mstr;

    if _n_ = 1 then mstr = var1;
    else
        mstr = trim(mstr)||trim(var1);
run;

Gotta love SAS!
 
Hi Nickdel,
If you're using SAS 9.1, then check out the CATT() and CATX() functions. They do this a little more succinctly.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top