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 2000, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 18 Feb 2000 09:10:33 -0500
Reply-To:     WHITLOI1 <WHITLOI1@WESTAT.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         WHITLOI1 <WHITLOI1@WESTAT.COM>
Subject:      Re: conditioned merging
Comments: To: Torben Haslund <Torben.Haslund@VBIOL.SLU.SE>
Content-Type: text/plain; charset=US-ASCII

Subject: conditioned merging Summary: Two step process required. Respondent: Ian whitlock <whitloi1@westat.com>

Torben Haslund <Torben.Haslund@VBIOL.SLU.SE> wrote

> I want to merge: > data set A with B, if B but not C exists > data set A with C, if C but not B exists > data set A with B and C, if B and C exist. > > data a; > if b and not c exist merge a b; > if c and not b exist merge a c; > if b and c exist merge a b c; > > .... but how do I do that?

The EXIST function will tell you whether the data exists or not, but it cannot be used in the same step as the MERGE because the compiler must be able to read the data dictionary of all referenced data sets. Hence there must be two steps. Here is example code.

data a ( keep = x ) b ( keep = x y ) ; y = 3 ; do x = 1 to 5 ; output ; end ; run ;

data _null_ ; if exist ( "b" ) then call symput ( "b" , "b" ) ; else call symput ( "b" , "" ) ; if exist ( "c" ) then call symput ( "c" , "c" ) ; else call symput ( "c" , "" ) ; run ;

data w ; merge a &b &c ; by x ; run ;

Ian Whitlock


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