It is possible to match Datasets using differents variables with merge?
If I have 3 DataSets (DS):
DS1 and DS2 can be matched by var1
DS2 and DS3 only by Var2 (Var2 has differente data than Var1)
I know that is possible in diferent data steps or using proc SQL, but I want to know if is possible with merge in one step or exists other method using SAS code.
MERGE won't do that at all. You can force a DATA step to do what you are asking, but it is not necessarily simple. And the complexities multiply if you have a possibility of mismatches or a possiblity of a many-to-one (or worse yet, many-to-many) match. Here are a couple of ideas.
In terms of speed and simplicity, I would probably go with the hash table. But nothing is simple. For example, what should happen if the hash table contains a data value that does not have a match either of the other two data sets?
Proc SQL is the exact tool for that task. Be aware however that for many-to-many merges it is not equivalent to the data step.
Since you can only have one BY statement in the data step, this is not possible.
Use SQL for doing that in one step. But be aware that joining multiple large tables in SQL will often perform horribly compared to a sequence of SORT and MERGE steps.
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 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.