BookmarkSubscribeRSS Feed
MV04
Obsidian | Level 7

Hi,

I have got two datasets as D1 and D2

D1

id2id1open_dateamt
12223412356701-Apr-095
12223412356710-Apr-094
12223412356701-May-092
12223412356701-Jun-105
12223412356701-Jul-101
12223412356701-Sep-102
12223412356701-Oct-106
12223412356703-Dec-124
13422112356802-Sep-116
13422212356802-Apr-095
13422212356812-Apr-094
13422212356811-May-092
13422212356812-Jun-105
13422212356802-Jul-10

1

 

D2

id2open_dateamt
12223402-Mar-096
12223411-Apr-097
12223402-May-094
12223405-Jun-091
12223402-Jul-105
12223405-Sep-103
12223404-Nov-108
13422111-Sep-112
13422210-May-095
13422225-May-093
13422226-May-095
13422228-May-097

 

Now the task is :

I need to take all those amounts from D2 where any date  per account from d1 > (all dates  from d2) The two datasets can be linked on D2.

all I am trying to create a macro which will compare the d1 and d2 on acc numbers and check the dates from d1 into d2 and whereever date from d1 is greater than d2 get the amount of the prior date

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This is not a job for a macro.

 

The solution can be done via merging the two data sets in a data step.

 

But before we provide a solution, show us the output data set you want from this.

--
Paige Miller
MV04
Obsidian | Level 7

The output dataset should be something like below

id1open_dateamt_d1amt_d2
12356701-Apr-0956
12356710-Apr-0947
12356701-May-0924
12356701-Jun-1051
12356701-Jul-1015
12356701-Sep-1023
12356701-Oct-1068
12356703-Dec-1242
12356802-Sep-1165
12356802-Apr-0953
12356812-Apr-0945
12356811-May-0927

 

so amt is the last amt prior to each date as you loop through the dates in between d1 and d2

so if we loop through open date in d1 then the dtes will be like 01-apr,02-apr,03-apr,04-apr,05-apr,06-apr and so on and these dates we need to compare with the open date from d2 so if the date say 01apr2009 from d1 falls between the dates 02ma2009 till 11apr2009 then return the amt at 02mar2009,if its not falling between those dates then check the next two dates (make sure the open dte in d2 is sorted in ascending order)

 

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
  • 2 replies
  • 515 views
  • 0 likes
  • 2 in conversation