<?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: DO WHILE LOOP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314242#M68412</link>
    <description>&lt;P&gt;Yes, it can be done with a do while.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While date &amp;lt; min(issue_date, today())&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't valid SAS syntax, I'll leave that to you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Nov 2016 08:45:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-11-25T08:45:44Z</dc:date>
    <item>
      <title>DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314237#M68411</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data set with data as BELOW:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;INVOICE_NO&lt;/TD&gt;&lt;TD&gt;ISSUE_DATE&lt;/TD&gt;&lt;TD&gt;CLOSE_DATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2016-09-08&lt;/TD&gt;&lt;TD&gt;2016-09-15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2016-09-09&lt;/TD&gt;&lt;TD&gt;2016-09-27&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2016-09-10&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2016-09-11&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2016-09-12&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;2016-09-13&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;2016-09-14&lt;/TD&gt;&lt;TD&gt;2016-09-29&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;2016-09-15&lt;/TD&gt;&lt;TD&gt;2016-10-06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;2016-09-16&lt;/TD&gt;&lt;TD&gt;2016-09-26&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;W need to generate table with new column REF_DATE. The REF_DATE should cotain all dates between ISSUE_DATE and CLOSE_DATE and if invoice is not CLOSED (CLOSE_DATE is null) max REF_DATE should be Today's date.&lt;/P&gt;&lt;P&gt;I can do this with DO loop but I would like to try DO WHILE, is there any chance to do this with DO WHILE?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 08:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314237#M68411</guid>
      <dc:creator>Arsene83</dc:creator>
      <dc:date>2016-11-25T08:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314242#M68412</link>
      <description>&lt;P&gt;Yes, it can be done with a do while.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The logic is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While date &amp;lt; min(issue_date, today())&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't valid SAS syntax, I'll leave that to you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 08:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314242#M68412</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-25T08:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314245#M68413</link>
      <description>&lt;P&gt;I thought so, but I'm doing somethig wrong. Could you check what's wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data DO_WHILE_OUT;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set DO_WHILE_IN ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;REF_DATE = ISSUE_DATE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do While (REF_DATE &amp;lt; min(CLOSE_DATE, Today()));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;REF_DATE = ISSUE_DATE+1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/P&gt;&lt;P&gt;FORMAT REF_DATE yymmdd10.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 09:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314245#M68413</guid>
      <dc:creator>Arsene83</dc:creator>
      <dc:date>2016-11-25T09:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314248#M68415</link>
      <description>&lt;P&gt;Well, the first thing which is wrong is not providing all the information. &amp;nbsp;Post test data in the form of a datastep - otherwise we can't see the structure. &amp;nbsp;Are those "date" variables dates, or are the text, text will fail. &amp;nbsp;Also post log messages, we don't know "whats wrong".&lt;/P&gt;
&lt;P&gt;Now in your issue:&lt;/P&gt;
&lt;PRE&gt;data have;
  length issue_date close_date $50;
  infile datalines missover;
  input invoice_no issue_date $ close_date $;
datalines;
1	2016-09-08	2016-09-15
3	2016-09-10	 
;
run;

data want;
  set have;
  do ref_date=input(issue_date,yymmdd10.) to ifn(close_date="",today(),input(close_date,yymmdd10.));
    output;
  end;
  format ref_date date9.;
run;
&lt;/PRE&gt;
&lt;P&gt;The above works, however what if you have partial dates, or the issue date is missing, or, as you are using text apparently for dates, they are not dates?&lt;/P&gt;
&lt;P&gt;Just to add, as you have a fixed start point, and a fixed end point, there is no beneifts to using do while.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 10:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314248#M68415</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-25T10:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314249#M68416</link>
      <description>&lt;P&gt;in your do while loop you have sending your program into an infinite loop &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first line in the loop should be&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REF_DATE = REF_DATE+1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Nov 2016 09:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314249#M68416</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-25T09:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314250#M68417</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/112791"&gt;@Arsene83&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I thought so, but I'm doing somethig wrong. Could you check what's wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data DO_WHILE_OUT;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set DO_WHILE_IN ;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;REF_DATE = ISSUE_DATE;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;do While (REF_DATE &amp;lt; min(CLOSE_DATE, Today()));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;REF_DATE = ISSUE_DATE+1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;FORMAT REF_DATE yymmdd10.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DO_WHILE_OUT;
set DO_WHILE_IN ;
REF_DATE = ISSUE_DATE;
do While (REF_DATE &amp;lt; min(CLOSE_DATE, Today()));
  *REF_DATE = ISSUE_DATE+1;
  * This statement is wrong, as REF_DATE will always be set to the same value, causing an endless loop;
  ref_date = ref_date + 1;
  * correct version;
  output;
end;
FORMAT REF_DATE yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Keep in mind that SAS code is case-insensitive, so there's no use in using capitals. Most contributors here find non-capitalized code more pleasing to the eyes.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 09:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314250#M68417</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-25T09:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314253#M68418</link>
      <description>&lt;P&gt;PS and if your new dataset should start with issue_date, a slight correction is necessary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data do_while_out;
set do_while_in ;
format ref_date yymmdd10.;
ref_date = issue_date;
do while (ref_date &amp;lt;= min(close_date, today()));
  output;
  ref_date = ref_date + 1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Nov 2016 09:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314253#M68418</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-25T09:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: DO WHILE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314271#M68423</link>
      <description>&lt;P&gt;Thanks !&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 11:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-WHILE-LOOP/m-p/314271#M68423</guid>
      <dc:creator>Arsene83</dc:creator>
      <dc:date>2016-11-25T11:07:45Z</dc:date>
    </item>
  </channel>
</rss>

