Hi,
I'm trying to add two tables with similar data but I have more than one possible match between them. Example below:
Table 1
Field 1 | Field 2 | Field 3 |
LA | Street 1 | House 1 |
LA | Street 2 | House 1 |
LA | Street 2 | House 2 |
NY | Street 1 | House 1 |
NY | Street 1 | House 2 |
NY | Street 2 | House 1 |
and Table 2
Field 1 | Field 2 | Field 3 | Code |
LA | Street 1 | House 1 | Code1 |
LA | Street 2 | House 1 | Code12 |
LA | Street 2 | House 2 | Code54 |
NY | Street 1 | Code15 | |
NY | Street 2 | Code43 | |
NY | Street 3 | Code67 |
I want to match the code on Table 2 to each row on Table 1 however for NY it doesn't have a field 3 specification and the code should be linked only to street number whatever the house number is.
I want the output to be something like this:
Field 1 | Field 2 | Field 3 | Code |
LA | Street 1 | House 1 | Code1 |
LA | Street 2 | House 1 | Code12 |
LA | Street 2 | House 2 | Code54 |
NY | Street 1 | House 1 | Code15 |
NY | Street 1 | House 2 | Code15 |
NY | Street 2 | House 1 | Code43 |
Is there any way I do this on SAS EG directly?
Thanks
I'm not sure what you mean by "do this in SAS EG directly", but you could accomplish this in several different ways in EG.
The simpliest (in my view) is to manually add a program node and then hand-write PROC SQL or data step code. But, you could also use Query Builder to join the tables and output two data sets (one with matches for both street and house, the other with matches where house is missing in table1) and then join them together.
Hi,
First, just add two variables in your TABEL1 as below:
temp_field2 = field2;
temp_field3 = field3;
And use the following code to merge back with tabel1 to add CODE information...
data both(drop = field2 field3 rename = (temp_field2 = field2 temp_field3 = field3));
merge one(in = a) two(in = b);
by field1 field2;
if a;
run;
-Urvish
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.