I've been using match merge for some time now without (known) issues. However, I have a problem with a set I'm running today.
My data sets and code:
DATA M;
INPUT VAR1 VAR2 ;
DATALINES;
x a
x b
x c;
DATA N;
INPUT VAR1 VAR3 ;
DATALINES;
x s
x t ;
DATA P;
MERGE M N;
BY VAR1
The desired result is as follows, and what I'm used to seeing for match merges:
VAR1 VAR2 VAR3
x a s
x a t
x b s
x b t
x c s
x c t
Instead I'm getting something I've never seen before. SAS appears to be merging the two sets by matching the first record of M with the first record of N, second to second. etc. But apprently once all the values of VAR3 have been used it simply repeats the last. As follows:
VAR1 VAR2 VAR3
x a s
x b t
x c t
I've never seen (or noted) this behavior on a match merge before. Perhaps I'm missing something - I'm self-taught and don't know where the holes are in my knowledge.
Thanks!
At each iteration of a datastep merge, a new observation is read from both datasets, if available within the BY group. The result you got is just what is expected. The easiest way to get the product of the two datasets within BY groups is with proc SQL :
proc sql;
create table p as
select m.*, n.var3
from m inner join n
on m.var1=n.var1;
quit;
PG
Thanks. I'd have to look back at my earlier work; I muyst have been doing one-to-many matches instead of a many-to-many like this one.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.