<?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 While loop understanding in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813431#M321046</link>
    <description>&lt;P&gt;I'm trying to understand the below step which was written by other programmer. I feel that this step can be written in better way. In the below step I want to know how the record count increases in the output dataset. Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;253        DATA WORK.BASELINE3;
254             SET BASELINE3;
255             POSTNG_DT = BAS_STRT_DT - 1;
256             DAYS_OF_PO = BAS_FINISH_DT - BAS_STRT_DT +1;
257             DO WHILE (BAS_FINISH_DT &amp;gt; POSTNG_DT);
258                   POSTNG_DT = intnx("day",POSTNG_DT,1);
259                   OUTPUT;
260             END;
261        RUN;

NOTE: There were 7779 observations read from the data set WORK.BASELINE3.
NOTE: The data set WORK.BASELINE3 has 21215 observations and 31 variables.
&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 May 2022 10:33:13 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2022-05-16T10:33:13Z</dc:date>
    <item>
      <title>Do While loop understanding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813431#M321046</link>
      <description>&lt;P&gt;I'm trying to understand the below step which was written by other programmer. I feel that this step can be written in better way. In the below step I want to know how the record count increases in the output dataset. Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;253        DATA WORK.BASELINE3;
254             SET BASELINE3;
255             POSTNG_DT = BAS_STRT_DT - 1;
256             DAYS_OF_PO = BAS_FINISH_DT - BAS_STRT_DT +1;
257             DO WHILE (BAS_FINISH_DT &amp;gt; POSTNG_DT);
258                   POSTNG_DT = intnx("day",POSTNG_DT,1);
259                   OUTPUT;
260             END;
261        RUN;

NOTE: There were 7779 observations read from the data set WORK.BASELINE3.
NOTE: The data set WORK.BASELINE3 has 21215 observations and 31 variables.
&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 10:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813431#M321046</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-05-16T10:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Do While loop understanding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813435#M321049</link>
      <description>&lt;P&gt;Since dates are counts of days, INTNX with "day" is usually overkill.&lt;BR /&gt;You can use an iterative DO loop instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do postng_dt = bas_strt_dt to bas_finish_dt;
  output;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first calculation of postng_dt serves no purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you run a loop for every observation read from baseline3 that includes an OUTPUT, you get multiple observations in the output dataset.&lt;/P&gt;
&lt;P&gt;The usual warning: overwriting a dataset in one step is dangerous and can cause you to lose all work up to this point.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 11:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813435#M321049</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-16T11:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Do While loop understanding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813441#M321050</link>
      <description>&lt;P&gt;Here's a technique to figure out what is happening and if it can be re-coded (as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;suggests)&lt;BR /&gt;&lt;BR /&gt;Create a simple example input dataset, then add PUT statements to the code, so you can see what is happening:&lt;BR /&gt;&lt;BR /&gt;Note: I added a "break" variable because I had a typo and the do loop went infinite on me.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data baseline3 ;
	infile cards ;
	input 
		bas_strt_dt  : date9.
		bas_finish_dt : date9. ;
cards ;
15May2022 20May2022
16May2022 17May2022
;


DATA WORK.BASELINE3;
break=0 ;
  SET BASELINE3;
  put bas_strt_dt= bas_finish_dt= bas_strt_dt= DATE. bas_finish_dt= DATE. ;
  POSTNG_DT = BAS_STRT_DT - 1;
  DAYS_OF_PO = BAS_FINISH_DT - BAS_STRT_DT +1;
  DO WHILE (BAS_FINISH_DT &amp;gt; POSTNG_DT);
    POSTNG_DT = intnx("day",POSTNG_DT,1);
	put bas_strt_dt= bas_finish_dt= POSTNG_DT= bas_strt_dt= DATE. bas_finish_dt= DATE. POSTNG_DT=DATE. ;
	
	break+1 ;
	if break &amp;gt; 10 then stop ;
    OUTPUT;
  END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 11:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813441#M321050</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-05-16T11:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Do While loop understanding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813459#M321055</link>
      <description>&lt;P&gt;Here is an easier way to implement your "BREAK" concept.&lt;/P&gt;
&lt;P&gt;SAS will allow you combine iterative DO and WHILE().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DO BREAK=1 to 10 WHILE (BAS_FINISH_DT &amp;gt; POSTNG_DT);
 ...
END;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 13:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813459#M321055</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T13:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Do While loop understanding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813461#M321056</link>
      <description>&lt;P&gt;No need to INTNX() when moving by DAY since dates are just number of days.&lt;/P&gt;
&lt;P&gt;If you need to move by some other interval that is not a constant amount, such as MONTH or YEAR, then it is less confusing to use an OFFSET integer so that your DO loop does not need WHILE() or UNTIL().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if you wanted to output one observation per month in an interval between a STARTDT and ENDDT variables you could do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  do offset=0 to intck('month',startdt,enddt);
    date = intnx('month',startdt,offset,'b');
    format date date9.;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 13:51:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-While-loop-understanding/m-p/813461#M321056</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-16T13:51:47Z</dc:date>
    </item>
  </channel>
</rss>

