LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 11 Feb 2010 09:25:41 -0800
Reply-To:   mlhoward@avalon.net
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Mary <mlhoward@AVALON.NET>
Subject:   Re: Join data horizontally
Content-Type:   text/plain; charset="UTF-8"

This is correct, and if you have a lot of variables here is the code from Data Null in May 2008 which renamed an entire data set:

data work.class; set sashelp.class; run; %let rename=; proc sql noprint; select cats(name,'=mds_',name) into :rename separated by ' ' from dictionary.columns where libname eq 'WORK' and memname = 'CLASS' ; quit; run; %put NOTE: RENAME=&rename; proc datasets; modify class; rename &rename; run; contents data=class; run; quit;

Actually, you might not want to rename your variable that matches between the two data sets; such as ID, thus the SQL pull to remove that variable from the list might be this: proc sql noprint; select cats(name,'=mds_',name) into :rename separated by ' ' from dictionary.columns where libname eq 'WORK' and memname = 'CLASS' and name not in ('ID'); quit;

You would probably want to assign a prefix to both files before merging, so that you remember which file the variable came from. Also, after you get that far, read up on the COALESCEC function, as it can give you one column with the first non-missing value between two values. I used to do this a lot when dealing with genetics data when two different labs did DNA results on the same genetic markers on the same individuals, and we wanted to make sure they were the same before merging, but sometimes they were different, or sometimes we had a result from one lab and a missing (not done) from the other lab.

-Mary

--- Mterjeson@RUSSELL.COM wrote:

From: "Terjeson, Mark" <Mterjeson@RUSSELL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Join data horizontally Date: Thu, 11 Feb 2010 08:53:34 -0800

Hi Suren,

Well, as we know, most languages do not allow more than one variable with the same variable name. However, for dataset one and two, you could distinguish them by renaming them to A1 and A2 and B1 and B2. The dataset option "rename" prior to a merge in a datastep, or mere renames when using SQL can accomplish this.

Hope this is helpful.

Mark Terjeson Investment Business Intelligence Investment Management & Research Russell Investments 253-439-2367

Russell Global Leaders in Multi-Manager Investing

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Suren gc Sent: Thursday, February 11, 2010 7:48 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Join data horizontally

I want to join data horizontally without any common columns replacing each other. I want to have the joined data set to have all the datasets side by side with each other. Data one; A B st 1 ts 2 Data two; A B C AR SE 44 TX SE 32 NY NE 30 Data three; Species Cost SW 32 HW 22

I want to join above three datasets in one single dataset with each sitting side by side with the other. My final dataset would be: A B A B C Species Cost st 1 AR SE 44 SW 32 ts 2 TX SE 32 HW 22 NY NE 30

Thanks, Suren


Back to: Top of message | Previous page | Main SAS-L page