BookmarkSubscribeRSS Feed
redfishJAX
Calcite | Level 5

The following script selects the first payment that meets the criteria of the given promise record by using a hash table.  I need to modify this to render ALL records in the payment table that meet the promise criteria.

 

So for the first record in promise (acctnum = 100 dated 3/15) - i would see two payments (dated 3/21 and 3/25) for that promise record in the output. no records would be output for the second observation (acctnum = 100 dated 3/21).

 

Can the below script modified to accomplish this?

 

 

 

data Promise ;
input acctnum  promisedate : mmddyy12. promiseamt (bwindow  ewindow ) (: mmddyy12.);
format promisedate bwindow ewindow mmddyy10.;
cards;
100  3/15/2015 100  3/15/2015 3/28/2015
100  3/21/2015 150  3/21/2015 4/1/2015
200  3/15/2015 100  3/15/2015 3/28/2015
200  3/21/2015 150  3/21/2015 4/1/2015
;
run;

 

data Payments ;
input acctnum  paydate  : mmddyy12. payamt ;
format       paydate   mmddyy10.;
cards;
100  3/21/2015 100
100  3/25/2015 150
100  5/25/2015 150
200  3/21/2015 100
200  3/25/2015 150
200  3/28/2015 150
200  5/25/2015 150
;
run;

data want;
 if _n_ eq 1 then do;
  if 0 then set Promise(keep=acctnum  bwindow ewindow);
  declare hash h(dataset:'Promise(keep=acctnum  bwindow ewindow)',multidata:'y');
  h.definekey('acctnum');
  h.definedata('bwindow','ewindow');
  h.definedone();
 end;
set  Payments;
rc=h.find();
do while(rc=0);
 if bwindow le paydate le ewindow then do;
                                          found=1;
                                                  ​  h.removedup();
                                          leave;
                                       end;
 rc=h.find_next();
end;
drop rc;
run;

4 REPLIES 4
Steelers_In_DC
Barite | Level 11

I am missing something, can you explain why the second record does not fall into the criteria? 

redfishJAX
Calcite | Level 5

Once a payment record/observation has been used..  i dont want to use it again for any further observation in the promise dataset. 

 

The first two obs of the payment dataset would go witht the first observation in the promise dataset. The second observation in the promise dataset would get no matches. 

Steelers_In_DC
Barite | Level 11

I was hoping someone else answered so I can see the solution.  I'm not the best person to answer this question but see if this gets the desired results, with the test data it works:

 

data want;
length acctnum 8. promisedate 8. promiseamt 8. bwindow 8. ewindow 8.;
if _N_ = 1 then do;
    declare hash e(dataset:'promise');
    e.definekey('acctnum');
    e.definedata('promisedate','promiseamt','bwindow','ewindow');
    e.definedone();
end;
set Payments;
drop rc;
rc = e.find();
if rc = 0 and bwindow <= paydate <= ewindow;
format promisedate bwindow ewindow mmddyy10.;
run;

redfishJAX
Calcite | Level 5

Thanks for your help.

 

I will give this a try and see how it works.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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