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;

 

 

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 826 views
  • 2 likes
  • 4 in conversation