BookmarkSubscribeRSS Feed
kpdoe
Calcite | Level 5
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;
ACCTDateTxt
111110/31/2022 
111102/28/2023ABC

 

Is this result achievable without having a matching date filed? Thanks in advance for any help!

3 REPLIES 3
ballardw
Super User

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!


 

vijaypratap0195
Obsidian | Level 7

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

Ksharp
Super User
/*
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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 625 views
  • 0 likes
  • 4 in conversation