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!

Merge Forename and Surname columns into one column

Status
Not open for further replies.

Katie6

Programmer
Jun 12, 2007
58
GB
Hi there,

I have a dataset (D1) with the following three columns:

ID
Forename
Surname

I'd like to create a new dataset (D2) using D1 which will contain the following columns:

ID
Name

I would like the Name column in D2 to be created by merging the Forename and Surname columns in D1, and I would like a dash (-) between the forename and surname, for example:

D1

ID /Forename / Surname
--------------------------
1 / John / Smith
2 / Anna / Jones


D2

ID / Name
-------------
1 / John - Smith
2 / Anna - Jones


Would any one be able to help me with this?

Many thanks,

Katie.




 
Code:
data d2;
  set d1;
   length name2-name4 $60;

   name1 = fname || ' - ' || sname;
   name2 = fname || ' - ' || sname;
   name3 = trim(left(fname)) || ' - ' || trim(left(sname));
   name4 = catx(' - ',fname,sname);
run;
Run this, and check out the differences in the results. The last one (name4) will only work if you're using SAS9.



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

Part and Inventory Search

Sponsor

Back
Top