|
Art,
I believe I encountered this phenomenon for the first time circa 1996 and
came up with the same workaround. However, since the competition for
resources in the system I was using then was extremely high and our files -
extremely large, it drove me up the wall (clock) to engage in the wasteful
I/O exercise just for this reason, so further workaround came in the form of
a view:
data mview / view = mview ;
merge one two ;
by a ;
run ;
data match ;
set mview ;
if b = 20 then c = 50 ;
run ;
Same result, but no need to rewrite the whole thing. If it is imperative to
keep everything in the same step (albeit in this case, I cannot think of a
good reason to insist on that), another, purely programmatic workaround is
available:
data match (drop = _:) ;
merge one two ;
by a ;
retain _c ;
if first.a then _c = c ;
if b = 20 then c = 50 ;
else c = _c ;
run ;
The problem with the latter is that it is rather obscure, because its intent
is overriding the default behavior of the software instead of attaining the
business purpose of the program.
Merry Christmas!
Kind regards
------------
Paul Dorfman
Jax, FL
------------
On Fri, 25 Dec 2009 12:34:30 -0500, Arthur Tabachneck <art297@NETSCAPE.NET>
wrote:
>Not quite expected results when doing a many-to-one merge in a datastep
that
>includes a subsetting condition (unless you do the subsetting condition in
a
>second datastep).
>
>Given the following two files:
>
>data one;
> input a b;
> datalines;
>10 10
>10 20
>10 30
>10 40
>10 50
>;
>
>data two;
> input a c;
> datalines;
>10 100
>;
>
>/*and merging them with a datastep that includes a subsetting condition:*/
>
>data match;
> merge one two;
> by a;
> if b = 20 then c = 50;
>run;
>
>/* will result in a file that looks like:
>
> Obs a b c
>
> 1 10 10 100
> 2 10 20 50
> 3 10 30 50
> 4 10 40 50
> 5 10 50 50
>*/
>
>The SAS note can be found at: http://support.sas.com/kb/24/453.html
>
>Art
|