LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 6 Nov 1998 02:25:32 +0000
Reply-To:     John Whittington <medisci@POWERNET.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         John Whittington <medisci@POWERNET.COM>
Subject:      Re: Merging files
Comments: To: Fearless <feldesman@HORMELUSA.NET>
Content-Type: text/plain; charset="us-ascii"

At 12:33 05/11/98 -0800, Fearless wrote:

>I have two SAS datasets that I want to merge. Dataset 1 has >2524 rows and 86 variables. Dataset 2 has 131 rows and 42 >variables. All 42 variables of dataset 2 are variables >found in Dataset 1 but none of the rows have matches. I >want to merge the two files into a 3rd file deleting all >variables that aren't in both files so that I have one file >with 2655 rows and 42 variables. > >A straightforward merge does not solve the problem. It >concatenates the two files but doesn't delete the variables >found in one file but not in the other. I don't do this >kind of stuff very often and I'm not finding anything >terribly helpful in the helpfiles or the manuals I have at >my disposal. > >Any suggestions on how best to proceed?

Probably the simplest approach, in outline, would be as follows:

1... write a simple macro (as often described on SAS-L) to examine the dictionary tables and create a macrovariable, say &list, consisting of a list of the names of the 42 variables in Dataset 2.

2... thenm simply,

data combine ; merge dataset1 (keep = &list) dataset2 ; by whatever ; run ;

Any help? If the variable list won't 'fit' in a single macrovariable, then a little refinement might be needed :-)



---------------------------------------------------------------- Dr John Whittington, Voice: +44 (0) 1296 730225 Mediscience Services Fax: +44 (0) 1296 738893 Twyford Manor, Twyford, E-mail: Buckingham MK18 4EL, UK ----------------------------------------------------------------

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