Can we use data steps for many to many merge.
My guesss is @Reezacorrectly interpretted your questions to be "Can I use the MERGE statement to get a cartesian product from a many to many merge." And for that, the answer is no.
Unfortunately, the merge statement will do a many-to-many merge, but the results are NOT a cartesian product. In fact, I've never seen an example where somebody actually wanted the result of a many-to-many merge. But it's good to know that merge will not error in this setting, and that the note about more than one dataset with repeats of BY values should be treated as an error. (Unfortunately I don't know a system option to make it an error).
524 data a;
525 do id=1,1,2;
526 a=cats('a',id);
527 output;
528 end;
529 run;
NOTE: The data set WORK.A has 3 observations and 2 variables.
530
531 data b;
532 do id=1,1,1,2;
533 b=cats('b',id);
534 output;
535 end;
536 run;
NOTE: The data set WORK.B has 4 observations and 2 variables.
537
538 data c;
539 merge a b;
540 by id;
541 put (id a b)(=);
542 run;
id=1 a=a1 b=b1
id=1 a=a1 b=b1
id=1 a=a1 b=b1
id=2 a=a2 b=b2
NOTE: MERGE statement has more than one data set with repeats of BY values.
NOTE: There were 3 observations read from the data set WORK.A.
NOTE: There were 4 observations read from the data set WORK.B.
NOTE: The data set WORK.C has 4 observations and 3 variables.
As a side note, there are ways to use the DATA step to create a cartesian product, just not with the MERGE statement.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.