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
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