I wish to merge two datasets: Data_A and Data_B using ID. I am only interested in observations in B with dates variable FDS_B that are within 14 days of each of the dates in A (FDS_A). The date format is MM/DD/YYYY. How do I improve the code below if I were to include FDS_A and FDS_B?
Data want;
Merge Data_A Data_B;
by ID;
run;
Maybe something along the lines of
Proc sql; create table want a select a,*, b.fds_b from data_a as a left join data_b as b on a.id=b.id where abs(a.fds_a-b.fds_b) le 14 ; quit;
Maybe. If your Fds variables are actual SAS date variables.
You do not mention any other variables from Data_b. You would have to explicitly list them using the b.variable syntax. If the variable is the same name as one in Data_A do you expect it to be a different variable or replace the value of the variable in the Data_a.
I am a bit concerned about exactly what you mean by "each of the dates in A". That could be taken different ways.
If the above suggestion doesn't come close then show some example data from each of the two sets and what you expect for the result.
I really appreciate your prompt response. Thanks. I had a detour on the approach and will get back for further clarifications.
Some of these questions will be simplified if we knew (for instance) that either a or b was limited to one obs per id. Is that the case/
If you provided some sample data in the form of a working data step, I think you will get some suggested code to address the request.
proc sql with inexact matching.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.