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 (August 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 21 Aug 2003 10:26:03 -0400
Reply-To:     Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject:      Re: Conditional merge
Comments: cc: "Janis.Jekabsons@DRESDNER-BANK.COM"
          <IMCEAMAILTO-Janis+2EJekabsons+40DRESDNER-BANK+2ECOM@WESTAT.com>
Content-Type: text/plain; charset="iso-8859-1"

In the message below I gave to ways to use UPDATE to solve the problem. The first one was faulty (must have been asleep for not construction my own test data). Here is corrected code.

data master ( drop = pb ) ; update one ( in = one ) two (in = two ) ; by a ; if one ; if active = 1 and two then b = pb ; run ;

data master ( drop = pb ) ; update master ( in = one ) three ( in = three ) ; by a ; if one ; if active = 2 and three then b = pb ; run ;

And here is better test data.

data one; a=1; b=0; active=1; output; a=2; b=0; active=1; output; a=3; b=0; active=1; output; a=4; b=0; active=2; output; a=5; b=0; active=2; output; run;

IanWhitlock@westat.com

-----Original Message----- From: Ian Whitlock Sent: Thursday, August 21, 2003 9:06 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Conditional merge

Janis,

I would use the update statement and an extra step rather than a merge.

data one; a=1; b=0; active=1; output; a=2; b=0; active=1; output; a=3; b=0; active=1; output; a=4; b=0; active=2; output; a=5; b=0; active=1; output; run;

data two; a=0; pb=-4; output; a=1; pb=-4; output; a=2; pb=-4; output; a=3; pb=-4; output; a=5; pb=-4; output; run;

data three; a=3; pb=2; output; a=4; pb=2; output; run;

data master ( drop = pb ) ; update one ( in = one ) two ; by a ; if one ; if active = 1 then b = pb ; run ;

data master ( drop = pb ) ; update master ( in = one ) three ; by a ; if one ; if active = 2 then b = pb ; run ;

/* or */

data trans ; set two ( in = two ) three ( in = three ) ; by a ; if two then pact = 1 ; else pact = 2 ; run ;

data master ( drop = p: ) ; update one ( in = m ) trans ; by a ; if m ; if active = pact then b = pb ; run ;

IanWhitlock@westat.com

-----Original Message----- From: Jekabsons, Janis [mailto:Janis.Jekabsons@DRESDNER-BANK.COM] Sent: Thursday, August 21, 2003 8:28 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Conditional merge

Hi group,

my brain is experiencing some performance hindrances today, so I am counting that your is tops ... Here's the question: I have two tables that I want to combine them with a third. The tables look as follows

data one; a=1; b=0; active=1; output; a=2; b=0; active=1; output; a=3; b=0; active=1; output; a=4; b=0; active=2; output; a=5; b=0; active=1; output; run;

data two; a=0; b=-4; output; a=1; b=-4; output; a=2; b=-4; output; a=3; b=-4; output; a=5; b=-4; output; run;

data three; a=3; b=2; output; a=4; b=2; output; run;

I want to take work.one as basis and join it with two and three using the rule: if active=1 then read from two else if active=2 then read from three

How could I do this?

Regards,

Janis Jekabsons Dresdner Bank AG CC RCO RMT MD SA Jürgen Ponto Platz 1, 8th Floor 60301 Frankfurt/Main Tel.: +49-(0)69-263-83648 Fax: +49-(0)69-263-59850 E-mail: janis.jekabsons@dresdner-bank.com


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