<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Do Loops with multiple sets using point= in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202339#M50512</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am stumped on how to get something to work.&lt;/P&gt;&lt;P&gt;I need to use point= do loop to accompish the following:&lt;/P&gt;&lt;P&gt;Dataset1: Promise&lt;/P&gt;&lt;P&gt;acctnum&amp;nbsp; promisedate promiseamt bwindow&amp;nbsp; ewindow&lt;BR /&gt;100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/15/2015 3/28/2015&lt;BR /&gt;100&amp;nbsp; 3/21/2015 150&amp;nbsp; 3/21/2015 4/1/2015&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dataset2: Payments&lt;BR /&gt;acctnum&amp;nbsp; paydate&amp;nbsp; payamt&lt;BR /&gt;100&amp;nbsp; 3/21/2015 100&lt;BR /&gt;100&amp;nbsp; 3/25/2015 150&lt;/P&gt;&lt;P&gt;I need the to evaluate each promise record by acctnum for a matching payment record (with same acctnum) within the date range (pdate and ewindow) and mark the promise found,&lt;BR /&gt;but I also need to mark the payment as used so it is not used again to evaluate the next promise record for that account number.&amp;nbsp; &lt;BR /&gt;What i have is below, but the issue is the first payment is used twice becuase it is the first payment in the specified range for both promises.&amp;nbsp; Anyone have any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data promisekey;&lt;BR /&gt; set promise;&lt;BR /&gt;by acctnum ewindow;&lt;BR /&gt;retain firstpr;&lt;BR /&gt;if first.acctnum then firstpr=_n_;&lt;BR /&gt;if last.acctnum then&lt;BR /&gt; do;&lt;BR /&gt;&amp;nbsp; lastpr=_n_;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data paymentkey;&lt;BR /&gt; set payments;&lt;BR /&gt;by acctnum paydate;&lt;BR /&gt;retain firstpy;&lt;BR /&gt;if first.acctnum then firstpy=_n_;&lt;BR /&gt;if last.acctnum then&lt;BR /&gt; do;&lt;BR /&gt;&amp;nbsp; lastpy=_n_;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data keys (keep=acctnum firstpr lastpr firstpy lastpy);&lt;BR /&gt; merge promisekey (in=a) paymentkey;&lt;BR /&gt; by acctnum;&lt;BR /&gt; if a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data final;&lt;BR /&gt; set keys;&lt;/P&gt;&lt;P&gt;do i=firstpr to lastpr;&lt;BR /&gt; set promise point=i;&lt;BR /&gt; format recdate yymmddn8.;&lt;BR /&gt; format bwindow yymmddn8.;&lt;BR /&gt; format ewindow yymmddn8.;&lt;BR /&gt; format paydate yymmddn8.;&lt;BR /&gt; format paid comma21.2;&lt;BR /&gt; recdate=.;&lt;BR /&gt; paid=.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if firstpy ne . then&lt;BR /&gt; do j=firstpy to lastpy until (found);&lt;BR /&gt; found=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set payments point=j ;&lt;BR /&gt;&amp;nbsp; if paydate ge pdate and paydate le ewindow&amp;nbsp; then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; recdate=paydate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; paid=amount;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; found=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This is what outputs (trimmed down with only some variables):&lt;/P&gt;&lt;P&gt;acctnum&amp;nbsp; promisedate promiseamt ewindow&amp;nbsp; found&amp;nbsp; paydate&amp;nbsp; payamt&lt;/P&gt;&lt;P&gt;100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/28/15&amp;nbsp; 1&amp;nbsp; 3/21/15&amp;nbsp; 100 &lt;BR /&gt;100&amp;nbsp; 3/21/2015 150&amp;nbsp; 4/1/2015 1&amp;nbsp; 3/21/15&amp;nbsp; 100 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This is what i need it to output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;acctnum&amp;nbsp; promisedate promiseamt ewindow&amp;nbsp; found&amp;nbsp; paydate&amp;nbsp; payamt&lt;/P&gt;&lt;P&gt;100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/28/15&amp;nbsp; 1&amp;nbsp; 3/21/15&amp;nbsp; 100 &lt;BR /&gt;100&amp;nbsp; 3/21/2015 150&amp;nbsp; 4/1/2015 1&amp;nbsp; 3/25/15&amp;nbsp; 150 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for the long winded request..&amp;nbsp; but wasn't sure how to explain and still not sure if I made it clear enough.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Apr 2015 14:33:07 GMT</pubDate>
    <dc:creator>redfishJAX</dc:creator>
    <dc:date>2015-04-23T14:33:07Z</dc:date>
    <item>
      <title>Do Loops with multiple sets using point=</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202339#M50512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am stumped on how to get something to work.&lt;/P&gt;&lt;P&gt;I need to use point= do loop to accompish the following:&lt;/P&gt;&lt;P&gt;Dataset1: Promise&lt;/P&gt;&lt;P&gt;acctnum&amp;nbsp; promisedate promiseamt bwindow&amp;nbsp; ewindow&lt;BR /&gt;100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/15/2015 3/28/2015&lt;BR /&gt;100&amp;nbsp; 3/21/2015 150&amp;nbsp; 3/21/2015 4/1/2015&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dataset2: Payments&lt;BR /&gt;acctnum&amp;nbsp; paydate&amp;nbsp; payamt&lt;BR /&gt;100&amp;nbsp; 3/21/2015 100&lt;BR /&gt;100&amp;nbsp; 3/25/2015 150&lt;/P&gt;&lt;P&gt;I need the to evaluate each promise record by acctnum for a matching payment record (with same acctnum) within the date range (pdate and ewindow) and mark the promise found,&lt;BR /&gt;but I also need to mark the payment as used so it is not used again to evaluate the next promise record for that account number.&amp;nbsp; &lt;BR /&gt;What i have is below, but the issue is the first payment is used twice becuase it is the first payment in the specified range for both promises.&amp;nbsp; Anyone have any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data promisekey;&lt;BR /&gt; set promise;&lt;BR /&gt;by acctnum ewindow;&lt;BR /&gt;retain firstpr;&lt;BR /&gt;if first.acctnum then firstpr=_n_;&lt;BR /&gt;if last.acctnum then&lt;BR /&gt; do;&lt;BR /&gt;&amp;nbsp; lastpr=_n_;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data paymentkey;&lt;BR /&gt; set payments;&lt;BR /&gt;by acctnum paydate;&lt;BR /&gt;retain firstpy;&lt;BR /&gt;if first.acctnum then firstpy=_n_;&lt;BR /&gt;if last.acctnum then&lt;BR /&gt; do;&lt;BR /&gt;&amp;nbsp; lastpy=_n_;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data keys (keep=acctnum firstpr lastpr firstpy lastpy);&lt;BR /&gt; merge promisekey (in=a) paymentkey;&lt;BR /&gt; by acctnum;&lt;BR /&gt; if a;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data final;&lt;BR /&gt; set keys;&lt;/P&gt;&lt;P&gt;do i=firstpr to lastpr;&lt;BR /&gt; set promise point=i;&lt;BR /&gt; format recdate yymmddn8.;&lt;BR /&gt; format bwindow yymmddn8.;&lt;BR /&gt; format ewindow yymmddn8.;&lt;BR /&gt; format paydate yymmddn8.;&lt;BR /&gt; format paid comma21.2;&lt;BR /&gt; recdate=.;&lt;BR /&gt; paid=.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if firstpy ne . then&lt;BR /&gt; do j=firstpy to lastpy until (found);&lt;BR /&gt; found=0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set payments point=j ;&lt;BR /&gt;&amp;nbsp; if paydate ge pdate and paydate le ewindow&amp;nbsp; then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; recdate=paydate;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; paid=amount;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; found=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt; output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This is what outputs (trimmed down with only some variables):&lt;/P&gt;&lt;P&gt;acctnum&amp;nbsp; promisedate promiseamt ewindow&amp;nbsp; found&amp;nbsp; paydate&amp;nbsp; payamt&lt;/P&gt;&lt;P&gt;100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/28/15&amp;nbsp; 1&amp;nbsp; 3/21/15&amp;nbsp; 100 &lt;BR /&gt;100&amp;nbsp; 3/21/2015 150&amp;nbsp; 4/1/2015 1&amp;nbsp; 3/21/15&amp;nbsp; 100 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This is what i need it to output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;acctnum&amp;nbsp; promisedate promiseamt ewindow&amp;nbsp; found&amp;nbsp; paydate&amp;nbsp; payamt&lt;/P&gt;&lt;P&gt;100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/28/15&amp;nbsp; 1&amp;nbsp; 3/21/15&amp;nbsp; 100 &lt;BR /&gt;100&amp;nbsp; 3/21/2015 150&amp;nbsp; 4/1/2015 1&amp;nbsp; 3/25/15&amp;nbsp; 150 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for the long winded request..&amp;nbsp; but wasn't sure how to explain and still not sure if I made it clear enough.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Apr 2015 14:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202339#M50512</guid>
      <dc:creator>redfishJAX</dc:creator>
      <dc:date>2015-04-23T14:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops with multiple sets using point=</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202340#M50513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think one solution could be to read Payments into a hash object.&lt;/P&gt;&lt;P&gt;Than read &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px; background-color: #ffffff;"&gt;Promise sequentially (set statement). For each promise you search the hash object (for example by iterating over it). If a match is found, you remove that entry from the hash object. So a subsequent search will not find it.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 10:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202340#M50513</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2015-04-28T10:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops with multiple sets using point=</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202341#M50514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&amp;nbsp; I will give that a try.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 11:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202341#M50514</guid>
      <dc:creator>redfishJAX</dc:creator>
      <dc:date>2015-04-28T11:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops with multiple sets using point=</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202342#M50515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have already done it before for somebody .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
data Promise ;
input acctnum&amp;nbsp; promisedate : mmddyy12. promiseamt (bwindow&amp;nbsp; ewindow ) (: mmddyy12.);
format promisedate bwindow ewindow mmddyy10.;
cards;
100&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/15/2015 3/28/2015
100&amp;nbsp; 3/21/2015 150&amp;nbsp; 3/21/2015 4/1/2015
200&amp;nbsp; 3/15/2015 100&amp;nbsp; 3/15/2015 3/28/2015
200&amp;nbsp; 3/21/2015 150&amp;nbsp; 3/21/2015 4/1/2015
;
run;

 

data Payments ;
input acctnum&amp;nbsp; paydate&amp;nbsp; : mmddyy12. payamt ;
format &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; paydate&amp;nbsp;&amp;nbsp; mmddyy10.;
cards;
100&amp;nbsp; 3/21/2015 100
100&amp;nbsp; 3/25/2015 150
100&amp;nbsp; 5/25/2015 150
200&amp;nbsp; 3/21/2015 100
200&amp;nbsp; 3/25/2015 150
200&amp;nbsp; 3/28/2015 150
200&amp;nbsp; 5/25/2015 150
;
run;

data want;
 if _n_ eq 1 then do;
&amp;nbsp; if 0 then set Promise(keep=acctnum&amp;nbsp; bwindow ewindow); 
&amp;nbsp; declare hash h(dataset:'Promise(keep=acctnum&amp;nbsp; bwindow ewindow)',multidata:'y');
&amp;nbsp; h.definekey('acctnum');
&amp;nbsp; h.definedata('bwindow','ewindow');
&amp;nbsp; h.definedone();
 end;
set&amp;nbsp; Payments;
rc=h.find();
do while(rc=0);
 if bwindow le paydate le ewindow then do;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; found=1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; h.removedup();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; leave;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;
 rc=h.find_next();
end;
drop rc;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2015 14:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202342#M50515</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-04-28T14:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops with multiple sets using point=</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202343#M50516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This worked great!&amp;nbsp; Thanks for you time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 17:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops-with-multiple-sets-using-point/m-p/202343#M50516</guid>
      <dc:creator>redfishJAX</dc:creator>
      <dc:date>2015-04-29T17:18:40Z</dc:date>
    </item>
  </channel>
</rss>

