BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sivastat08
Pyrite | Level 9

Hi ,

While Left Joining two data sets ,output of a data set should contains only exactly matched and whatever the observations not matched it should pick previous record(Date).Could you please help me on getting this.

Attached excel files

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Try this:

 

proc sql;
select left.transId, workdate, snapDate
from
left left join right on left.transId=right.transId and workDate >= snapDate
group by left.transId, left.workDate
having snapDate = max(snapDate);
quit;
PG

View solution in original post

6 REPLIES 6
ballardw
Super User

And the output should look like what for that input?

 

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

Kurt_Bremser
Super User

If you need help with Excel, you should consult a Microsoft-oriented forum.

If you need help with SAS datasets, please provide such in a usable way (data steps with datelines), so we have a clear picture of what you are working with.

PGStats
Opal | Level 21

Try this:

 

proc sql;
select left.transId, workdate, snapDate
from
left left join right on left.transId=right.transId and workDate >= snapDate
group by left.transId, left.workDate
having snapDate = max(snapDate);
quit;
PG
sivastat08
Pyrite | Level 9

Thanks for your support sir.

 

The code is working fine.

 

Here is my code

 

proc sort data= Test_A;by transId workDate;run;
proc sort data= Test_B;by transId snapDate;run;

 

proc sql;

create table New as
select lft.transId, lft.workdate, Rgt.snapDate
from work.Test_A lft
left join TEST_B Rgt on lft.transId= Rgt.transId and lft.workDate >= Rgt.snapDate
group by lft.transId, lft.workDate
having Rgt.snapDate = max(Rgt.snapDate);
quit;

 

 

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 6 replies
  • 1350 views
  • 2 likes
  • 4 in conversation