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 (January 2004, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 3 Jan 2004 08:05:37 -0800
Reply-To:     Bill McKirgan maxsfolks <bill-mckirgan@UIOWA.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Bill McKirgan maxsfolks <bill-mckirgan@UIOWA.EDU>
Organization: http://groups.google.com
Subject:      Re: Merge and delete (Sas Newbie)
Content-Type: text/plain; charset=ISO-8859-1

/* Hi randistan69@hotmail.com (Microstructure),

If I understand you correctly, you have data in ONE that you want to include in TWO; however, you would like to exclude records from ONE that aren't in TWO? If this is so, you don't need to delete records, just filter them out during the merge using the IN= trick.

I see you already have at least two helpful examples posted in reply to your question, and perhaps a few sent to you off list. Here's an attempt at a datastep solution using and some fabricated data.

I assume you might have duplicates of company symbols (variable A) in both datasets, but no duplications by the combination of variable 'A' and the DATE variable.

Remember to check the log for the note:

"NOTE: MERGE statement has more than one data set with repeats of BY values"

If you see this in the log after you perform the merge on your data, then you probably need to define another BY variable on the merge, or get rid of duplicates in dataset TWO.

Hope this helps.

Best wishes to you and all SAS-L Friends in the new year.

Bill McKirgan

*/

options nocenter nodate nonumber;

data one; input date : mmddyy10. a $ b m n ; cards4; 1/1/2000 a 1 2 3 1/2/2000 b 2 3 6 1/3/2001 c 3 4 7 2/1/2000 z 1 2 6 3/2/2000 y 6 8 6 2/3/2001 x 3 4 3 3/4/2002 w 4 5 8 4/1/2000 z 2 2 2 5/2/2000 y 2 6 6 1/4/2002 d 4 5 8 1/1/2000 e 1 2 3 1/2/2000 f 2 3 6 1/3/2001 g 3 4 7 1/4/2002 h 4 5 8 1/1/2000 z 1 2 3 1/2/2000 y 2 3 6 1/3/2001 x 3 4 7 1/4/2002 w 4 5 8 ;;;; run; proc sort; by a date; run;

data two; input date : mmddyy10. a $ c k j ; cards4; 1/1/2000 z 1 2 3 1/2/2000 y 5 3 9 1/3/2001 x 3 4 7 1/4/2002 w 4 9 8 2/1/2000 z 1 2 6 3/2/2000 y 6 8 6 2/3/2001 x 3 4 3 3/4/2002 w 4 5 8 4/1/2000 z 2 2 2 5/2/2000 y 2 6 6 ;;;; run; proc sort; by a date; run;

/* IN= renames the variable IN thus providing a means to filter records based on their source. */

data matches; merge one (in=inone) two (in=intwo) ; by a;

if inone and intwo; format date date7.; run;

proc print; by a; id a; run;

===output====

The SAS System

a date b m n c k j

w 04JAN02 4 5 8 4 9 8 04MAR02 4 5 8 4 5 8

x 03JAN01 3 4 7 3 4 7 03FEB01 3 4 3 3 4 3

y 02JAN00 2 3 6 5 3 9 02MAR00 6 8 6 6 8 6 02MAY00 2 6 6 2 6 6

z 01JAN00 1 2 3 1 2 3 01FEB00 1 2 6 1 2 6 01APR00 2 2 2 2 2 2

=============

randistan69@hotmail.com (Microstructure) wrote in message news:<751633cc.0401022239.4a091d54@posting.google.com>... > Hey guys: > I have two files: > File One has variables: Date Variable A Variable B Variable M > Variable N... > File Two has variables: Date Variable A Variable C Variable K > Variable J.... > Variable A is the Company Symbol. The Company Symbol appearing in > File Two is a subset of the of Variable A (Company Symbol) appearing > in File 1. I want to keep only the common company symbols in these > files and delete the others. > Any suggestions. Do you need more information???


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