data A;
input ACCT Date mmddyy10.;
format Date mmddyy10.;
datalines;
1111 10/31/2022
1111 02/26/2023
;
run;
/* Creating Dataset B */
data B;
input ACCT Txt $ Src_Date mmddyy10.;
format Src_Date mmddyy10.;
datalines;
1111 ABC 03/23/2023
;
run;
ACCT | Date | Txt |
1111 | 10/31/2022 | |
1111 | 02/28/2023 | ABC |
Is this result achievable without having a matching date filed? Thanks in advance for any help!
Why do you have a date in the example of what you want of 2/28/2023? None of the data you show has that in the source.
You probably should provide larger example data sets, along with the rule(s) involved in matching. I suspect I can write something that would work for case of exactly two records and exactly one record in the other set that would not extend at all.
If, as I suspect, the definition is going to involve some sort of "closest" date rule then you need to be very careful in defining how multiple dates that might be the same number of days apart are chosen. Consider a date of 15 Mar 2023 in one set and then other with same ACCT but dates of 13 Mar 2023 and 17 Mar 2023. Both are two days from 15 Mar. So which gets chosen and why.
@kpdoe wrote:
data A; input ACCT Date mmddyy10.; format Date mmddyy10.; datalines; 1111 10/31/2022 1111 02/26/2023 ; run; /* Creating Dataset B */ data B; input ACCT Txt $ Src_Date mmddyy10.; format Src_Date mmddyy10.; datalines; 1111 ABC 03/23/2023 ; run;
ACCT Date Txt 1111 10/31/2022 1111 02/28/2023 ABC
Is this result achievable without having a matching date filed? Thanks in advance for any help!
Your question is not clear. Can you also provide the criteria to join the 2 datasets.
It will be more clear if you can also provide an example over a larger dataset.
-Vijay
/*
I think you should post more data or example to
illustrate what you are looking for.
*/
data want;
merge A B(keep=ACCT txt rename=(txt=_txt));
by ACCT;
if last.ACCT then txt=_txt;
drop _txt;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: