<?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 Re: Could you help to understand this DoW loop code? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103017#M28837</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mirisage,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't quite understand how the DOW loop works.&amp;nbsp; What you appear to be missing is that the value assigned to the newly created variable is retained across all of the records.&amp;nbsp; Records 2, 3, 5, 6 and 7 don't meet your condition, thus the pdv will only reflect the value that had been assigned when either record 2 or record 4 was processed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When record 4 is processed, the value of 28feb2010 is replaced with 28feb2011.&amp;nbsp; Since you include an output statement in the loop, only the last record triggers a record to be output.&amp;nbsp; In your case, it is record 7 along with the value of &lt;SPAN style="color: #000000; font-family: 'Courier New'; background-color: #ffffff;"&gt;Last_NPNA_Start_Month&lt;/SPAN&gt; that was assigned when record 4 was processed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Oct 2012 18:00:28 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2012-10-22T18:00:28Z</dc:date>
    <item>
      <title>Could you help to understand this DoW loop code?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103016#M28836</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;Hi SAS Forum,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;I tried to understand what is going on in this dow loop (Soren is acknowledged) by applying it in a single account dataset which has multiple months. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;Objective of the dow was to create a new variable which identifies the last date where the account changes to NPNA.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 10pt; background: white; text-decoration: underline; font-family: 'Arial Narrow';"&gt;Answer: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 10pt;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bank_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Account_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Last_NPNA_Start_Month&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 10pt;"&gt;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; 10&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; 4444444444&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: aqua;"&gt;28FEB2011&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;This is correct because the “last date where the account changes to NPNA is 28FEB2011.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;But how it happened. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; text-decoration: underline;"&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; text-decoration: underline;"&gt;Data set (see the order of the dates are mixed).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;Data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; set_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;informat&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; Current_date &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 11pt;"&gt;date9.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;Input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; Bank_number &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp; Current_date&amp;nbsp;&amp;nbsp; Account_number $&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;14&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;23&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp; Balance &lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;25&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;-&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;26&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp; product $&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;28&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;40&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; Arrears_Band $&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;42&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;-&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;48&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; Current_date &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 11pt;"&gt;date9.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 31DEC2010 4444444444 25 Personal Loan NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 31MAR2011 4444444444 18 Personal Loan NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 31JAN2011 4444444444 18 Personal Loan 1 – 30&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 31MAY2011 4444444444 85 Personal Loan Current&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 30APR2011 4444444444 18 Personal Loan NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 28FEB2011 4444444444 18 Personal Loan NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 11pt;"&gt;10 28FEB2010 4444444444 25 Personal Loan NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;I first sorted the data set by a combination of 3 variables that would make a unique ID.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;sort&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;=set_3 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; = c;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; bank_number account_number&amp;nbsp; current_date;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;This is the sorted data set. We should use this to answer our question, I think,&amp;nbsp; because the&amp;nbsp; order of current_date in the unsorted data set is mixed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;STRONG style="color: #993366;"&gt;Obs Current_date Bank_number Account_number Balance product Arrears_Band&lt;/STRONG&gt;&lt;SPAN style="color: #0000ff;"&gt; (variable headings)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="0" cellspacing="0" style="border: #4f493b 1pt solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;1&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;28FEB2010&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;25&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;31DEC2010&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;25&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;3&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;31JAN2011&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;18&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;1 – 30&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;28FEB2011&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;18&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;31MAR2011&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;18&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;6&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;30APR2011&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;18&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;NPNA&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;7&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;31MAY2011&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;10&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;4444444444&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P align="right" style="text-align: right;"&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;85&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD nowrap="nowrap" valign="top"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Times New Roman';"&gt;Current&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&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;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt;Then the dow loop was applied.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; last_start_npna;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;do&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;until&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(last.account_number);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; c ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; bank_number account_number arrears_band &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;notsorted&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; first.Arrears_band &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Arrears_band=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;'NPNA'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Last_NPNA_Start_Month = Current_Date;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: yellow; color: blue;"&gt;putlog&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: yellow; color: purple;"&gt;"(1)"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;&amp;nbsp; _all_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Last_NPNA_Start_Month &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal;"&gt;date9.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;keep&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; bank_number account_number Last_NPNA_Start_month;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;; &lt;/SPAN&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt;Output generated is this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bank_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Account_number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Last_NPNA_Start_Month&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt;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; 10&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; 4444444444&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; &lt;SPAN style="color: #ff00ff;"&gt;28FEB2011&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;This is correct because the “last date where the account changes to NPNA is 28FEB2011.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt;But how it happened. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: white; color: black;"&gt;I tried with introducing &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: blue;"&gt;putlog&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: yellow; color: purple;"&gt;"(1)"&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;&amp;nbsp; _all_&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; which generated this log.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;I intentionally numbered them as (1) to (7) to lead my question.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; (1)last.account_number=0 Current_date=28FEB2010 Bank_number=10 Account_number=4444444444 Balance=25 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Arrears_Band=NPNA&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; FIRST.Bank_number=1 LAST.Bank_number=0 FIRST.Account_number=1 &lt;SPAN style="background: yellow;"&gt;FIRST.Arrears_Band=1&lt;/SPAN&gt; LAST.Arrears_Band=0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month=28FEB2010&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(2)last.account_number=0 Current_date=31DEC2010 Bank_number=10 Account_number=4444444444 Balance=25 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Arrears_Band=NPNA&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; FIRST.Bank_number=0 LAST.Bank_number=0 FIRST.Account_number=0 &lt;SPAN style="background: yellow;"&gt;FIRST.Arrears_Band=0&lt;/SPAN&gt; LAST.Arrears_Band=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month=28FEB2010&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(3)last.account_number=0 Current_date=31JAN2011 Bank_number=10 Account_number=4444444444 Balance=18 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Arrears_Band=1 - 30&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; FIRST.Bank_number=0 LAST.Bank_number=0 FIRST.Account_number=0 &lt;SPAN style="background: yellow;"&gt;FIRST.Arrears_Band=1 LAST.Arrears_Band=1&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month=28FEB2010&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(4)last.account_number=0 Current_date=28FEB2011 Bank_number=10 Account_number=4444444444 Balance=18 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Arrears_Band=NPNA&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; FIRST.Bank_number=0 LAST.Bank_number=0 FIRST.Account_number=0 &lt;SPAN style="background: yellow;"&gt;FIRST.Arrears_Band=1&lt;/SPAN&gt; LAST.Arrears_Band=0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month=28FEB2011&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(5)last.account_number=0 Current_date=31MAR2011 Bank_number=10 Account_number=4444444444 Balance=18 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Arrears_Band=NPNA FIRST.Bank_number=0 LAST.Bank_number=0 FIRST.Account_number=0 FIRST.Arrears_Band=0 LAST.Arrears_Band=0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Last_NPNA_Start_Month=28FEB2011 _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(6)last.account_number=0 Current_date=30APR2011 Bank_number=10 Account_number=4444444444 Balance=18 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Arrears_Band=NPNA FIRST.Bank_number=0 LAST.Bank_number=0 FIRST.Account_number=0 FIRST.Arrears_Band=0 LAST.Arrears_Band=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Last_NPNA_Start_Month=28FEB2011 _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;(7)last.account_number=1 Current_date=31MAY2011 Bank_number=10 Account_number=4444444444 Balance=85 product=Personal Loan&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Arrears_Band=Current&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; FIRST.Bank_number=0 LAST.Bank_number=1 FIRST.Account_number=0 &lt;SPAN style="background: yellow;"&gt;FIRST.Arrears_Band=1 LAST.Arrears_Band=1&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month=28FEB2011&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; _ERROR_=0 _N_=1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;Question:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; background: aqua; font-size: 12pt;"&gt;See log (1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow'; font-size: 12pt;"&gt;When DOW hits first record, dow condition is satisfied. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Because first.Arrears_band = 1 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Arrears_band=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;'NPNA'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Arial Narrow';"&gt;So, the &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month= &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Current_date&amp;nbsp;&amp;nbsp; which is &lt;SPAN style="background: fuchsia;"&gt;28FEB2010&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;This is correct and I understand it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: aqua; color: black; font-size: 12pt;"&gt;But see log (2)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;When DoW hits the second record, it doesn’t satisfy the condition.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Because first.Arrears_band = 0 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Arrears_band=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;'NPNA'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;But still the log says &lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month=28FEB2010&amp;nbsp; for the second record too.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;How come?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: aqua; color: black;"&gt;see log (4)&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; this is the turning point.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;first.Arrears_band = 1 &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;and&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Arrears_band=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple;"&gt;'NPNA'&lt;/SPAN&gt; (satisfy our condition).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;SPAN style="font-family: 'Arial Narrow';"&gt;So, the &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: yellow; color: black;"&gt;Last_NPNA_Start_Month= &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;Current_date&amp;nbsp;&amp;nbsp; which is &lt;SPAN style="background: lime;"&gt;28FEB2011&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;This is correct and I understand it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;But in subsequent records, even when our condition is not satisfied log continues to say &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 12pt; background: yellow; font-family: 'Courier New';"&gt;Last_NPNA_Start_Month=28FEB2011&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 12pt; background: yellow; font-family: 'Courier New';"&gt;How come?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG style="color: #008000; text-decoration: underline;"&gt;Last question:&lt;/STRONG&gt;&lt;/SPAN&gt; Now SAS has two dates that satisfy our condition, &lt;SPAN style="background: fuchsia;"&gt;28FEB2010&lt;/SPAN&gt; and &lt;SPAN style="background: lime;"&gt;28FEB2011&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;But how has SAS decided to output &lt;SPAN style="background: lime;"&gt;28FEB2011&lt;/SPAN&gt; for us which is our correct answer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;Your help to understand this is greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;Mirisage&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Arial Narrow';"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 17:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103016#M28836</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-10-22T17:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Could you help to understand this DoW loop code?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103017#M28837</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mirisage,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't quite understand how the DOW loop works.&amp;nbsp; What you appear to be missing is that the value assigned to the newly created variable is retained across all of the records.&amp;nbsp; Records 2, 3, 5, 6 and 7 don't meet your condition, thus the pdv will only reflect the value that had been assigned when either record 2 or record 4 was processed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When record 4 is processed, the value of 28feb2010 is replaced with 28feb2011.&amp;nbsp; Since you include an output statement in the loop, only the last record triggers a record to be output.&amp;nbsp; In your case, it is record 7 along with the value of &lt;SPAN style="color: #000000; font-family: 'Courier New'; background-color: #ffffff;"&gt;Last_NPNA_Start_Month&lt;/SPAN&gt; that was assigned when record 4 was processed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 18:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103017#M28837</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-22T18:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Could you help to understand this DoW loop code?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103018#M28838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't have to use the DoW or any other programming patterns until you feel comfortable with the data step. Here is a non-DoW version. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: Consolas, Courier New; font-size: 90%; line-height: 1.1;"&gt;&lt;SPAN style="color: #0000ff;"&gt;ods&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;_all_&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;close&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;ods&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;listing&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;options&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;nocenter&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;/* test data */&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; one;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;input&lt;/SPAN&gt;&lt;SPAN&gt; bank date :&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;date9.&lt;/SPAN&gt;&lt;SPAN&gt; acc $ bal prod :&amp;amp; &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;$13.&lt;/SPAN&gt;&lt;SPAN&gt; band :&amp;amp; &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;$7.&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;format&lt;/SPAN&gt;&lt;SPAN&gt; date &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;date10.&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #0000ff;"&gt;cards&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 31DEC2010 4444444444 25 Personal Loan&amp;nbsp; NPNA&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 31MAR2011 4444444444 18 Personal Loan&amp;nbsp; NPNA&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 31JAN2011 4444444444 18 Personal Loan&amp;nbsp; 1 - 30&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 31MAY2011 4444444444 85 Personal Loan&amp;nbsp; Current&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 30APR2011 4444444444 18 Personal Loan&amp;nbsp; NPNA&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 28FEB2011 4444444444 18 Personal Loan&amp;nbsp; NPNA&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;10 28FEB2010 4444444444 25 Personal Loan&amp;nbsp; NPNA&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;sort&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;=one &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;out&lt;/SPAN&gt;&lt;SPAN&gt;=two;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;by&lt;/SPAN&gt;&lt;SPAN&gt; bank acc date;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;/* flag the last date where the account changes to npna */&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; three;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;set&lt;/SPAN&gt;&lt;SPAN&gt; two;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;by&lt;/SPAN&gt;&lt;SPAN&gt; bank acc band &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;notsorted&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;retain&lt;/SPAN&gt;&lt;SPAN&gt; since &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; first.acc &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;call&lt;/SPAN&gt;&lt;SPAN&gt; missing(since);&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; first.band and band = &lt;/SPAN&gt;&lt;SPAN style="color: #800080;"&gt;"NPNA"&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt;&lt;SPAN&gt; since = date;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; last.acc &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;then&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;output&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;keep&lt;/SPAN&gt;&lt;SPAN&gt; bank acc since;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;format&lt;/SPAN&gt;&lt;SPAN&gt; since &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;date10.&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;print&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;data&lt;/SPAN&gt;&lt;SPAN&gt;=three;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;/* on lst&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; bank&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; acc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; since&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 44444444&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 28FEB2011&lt;/SPAN&gt;&lt;BR /&gt; &lt;SPAN style="color: #008000;"&gt;*/&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 21:16:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103018#M28838</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2012-10-22T21:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Could you help to understand this DoW loop code?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103019#M28839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Art and Chang,&lt;/P&gt;&lt;P&gt;Many thanks to both of you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;I think I am now much better than where I was originally. Thanks again for your nice explanation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Chang,&lt;/P&gt;&lt;P&gt;Thank you very much for your nice alternative way of doing the same thing, &lt;/P&gt;&lt;P&gt;Could I ask an additional question.&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt;I always have this confusion. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt;1) In the follwing code, Yellow highlighted place is the first time SAS hits the variable called “since”. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt;We have never said SAS what is “since” and how it was derived such as since = bank + 8 or anything like that. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt;But SAS understands before hand what is since. How come?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: red;"&gt;2). Blue highlighted place is the second place SAS hits the variable called “since”.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: red;"&gt; Still SAS was not told by us what is “since” and how “since” was created. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: red;"&gt; But SAS never questions you asking “Hey first define what is “since” before you ask me to do anything involving the variable since” &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: red;"&gt; If you have time, could you please elaborate a bit.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: blue;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy;"&gt;data&lt;/STRONG&gt; three;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: blue;"&gt;set&lt;/SPAN&gt; two;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: blue;"&gt;by&lt;/SPAN&gt; bank acc band &lt;SPAN style="color: blue;"&gt;notsorted&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background: yellow; color: blue;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="background: yellow;"&gt; since &lt;STRONG style="color: teal;"&gt;.&lt;/STRONG&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: aqua; color: blue;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background: aqua;"&gt; first.acc &lt;SPAN style="color: blue;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="color: blue;"&gt;call&lt;/SPAN&gt; missing(since);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: blue;"&gt;if&lt;/SPAN&gt; first.band and band = &lt;SPAN style="color: purple;"&gt;"NPNA"&lt;/SPAN&gt; &lt;SPAN style="color: blue;"&gt;then&lt;/SPAN&gt; since = date;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: blue;"&gt;if&lt;/SPAN&gt; last.acc &lt;SPAN style="color: blue;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="color: blue;"&gt;output&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: blue;"&gt;keep&lt;/SPAN&gt; bank acc since;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: blue;"&gt;format&lt;/SPAN&gt; since &lt;SPAN style="color: teal;"&gt;date10.&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy;"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Thank you for your time and expertise.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Mirisage&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Oct 2012 01:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103019#M28839</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-10-25T01:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Could you help to understand this DoW loop code?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103020#M28840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;(NOTE: We are taking as given that the variable SINCE is NOT in the dataset TWO referenced in the second line of the data step.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS will define the variable type for you based on how you use it.&amp;nbsp; If it cannot figure it out it will make it numeric.&amp;nbsp; It will also try to assign the length of a character variable for you.&amp;nbsp; Most of the time this will do what you want. This makes it much easier to write a program than in languages that require definition of everything. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case because you told it to initialize SINCE to numeric missing in the RETAIN statement in knows 100% that you meant for SINCE to be numeric.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you do not include the initial value in the RETAIN statement then the data step compiler does not know whether SINCE is numeric or character.&amp;nbsp; So the next time it appears as an argument to the MISSING() function.&amp;nbsp; That does not help as the missing function can take both numeric and character arguments.&amp;nbsp; So then it sees it assigned the value of the DATE variable in the next line.&amp;nbsp; So SINCE would be given the same type and length as the DATE variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Oct 2012 02:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103020#M28840</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-25T02:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: Could you help to understand this DoW loop code?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103021#M28841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;Thank you very much for this clarification.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is very helpful.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Mirisage &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 28 Oct 2012 17:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Could-you-help-to-understand-this-DoW-loop-code/m-p/103021#M28841</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-10-28T17:35:38Z</dc:date>
    </item>
  </channel>
</rss>

