<?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: Use a Do Loop to Adjust and Output Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557462#M155407</link>
    <description>&lt;P&gt;This didn't quite work - when I use just the first observation as have, this logic simply outputs the first observation without adjusting the date_of_service.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
do until (date_of_service ge '01Jan2019'd);
		output want;
	date_of_service = date_of_service + 90; 

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I move the output statement to where it was before, it again outputs the first observation, but changes the date_of_service to 4/25.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
do until (date_of_service ge '01Jan2019'd);
	date_of_service = date_of_service + 90; 
	output want;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I put an output statement in &lt;EM&gt;both&lt;/EM&gt; places, it only outputs the first observation without adjusting the date_of_service.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
do until (date_of_service ge '01Jan2019'd);
	output want;
	date_of_service = date_of_service + 90; 
	output want;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS Enterprise Guide, and submitting the code using the "Run Selection" option. I used the Generic SAS Editor to create the code. These are questions you had asked me to answer in another thread, so I figured I would post them here as well in case it is helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current version: 9.04.01M5P091317&lt;/P&gt;&lt;P&gt;Operating System: LIN X64&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2019 14:52:22 GMT</pubDate>
    <dc:creator>theponcer</dc:creator>
    <dc:date>2019-05-09T14:52:22Z</dc:date>
    <item>
      <title>Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557301#M155329</link>
      <description>&lt;P&gt;I am trying to figure out how much business I would have if all of my customers received oil changes at 90 day intervals. I have a data set that shows me when they have changed their oil in the past, but am having a hard time figuring out how to extrapolate future oil changes from the first oil change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29342i62973F812A344B1E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to do this? I am guessing it is something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;&lt;BR /&gt;by Name Car Date_of_Service;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data have2;&lt;BR /&gt;set have;&lt;BR /&gt;by Name Car Date_of_Service;&lt;BR /&gt;if first.Car=1 then output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;
set have2;
by name car;
do while (date_of_service lt '01Jan2019'd);
	if first.car=1 then output want; 
	date_of_service = date_of_service + 90; 
	output want;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To be clear, I want the code to look at the first observation and output it to "want". Then, I want it to change the date_of_service to 90 days in the future and output that observation. Then, I want it to look at the observation it just output - if that date_of_service is in the same year, then I want it to change the date_of_service to 90 days in the future. If the new date_of_service is in the same year, the new observation should be output, and the loop will continue. If not, the loop will move on to the first record of the next name/car combination.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 22:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557301#M155329</guid>
      <dc:creator>theponcer</dc:creator>
      <dc:date>2019-05-08T22:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557305#M155331</link>
      <description>&lt;P&gt;Since I don't have your data to test, I will recommend a change (but there may be other problems as well)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
by name car;
do while (date_of_service lt '01Jan2019'd);
	if first.car then do;
	    date_of_service = date_of_service + 90; 
	    output want;
    end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 22:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557305#M155331</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-08T22:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557307#M155333</link>
      <description>&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 22:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557307#M155333</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-08T22:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557308#M155334</link>
      <description>&lt;P&gt;I tried this too - unfortunately, it only outputs one record, and only after modifiying it. I suppose not outputting the first record is fine because I can just append the first records in a separate step, but I DO need those other records .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I start from 1/25, I would need the following records:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1/25&lt;/P&gt;&lt;P&gt;4/25&lt;/P&gt;&lt;P&gt;7/24&lt;/P&gt;&lt;P&gt;10/22&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This way only outputs 4/25!&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 22:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557308#M155334</guid>
      <dc:creator>theponcer</dc:creator>
      <dc:date>2019-05-08T22:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557403#M155391</link>
      <description>&lt;P&gt;At this point, you need to provide us with (a portion of) your actual data, using the method linked to by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 11:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557403#M155391</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T11:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557408#M155392</link>
      <description>&lt;P&gt;Should be easy enough. Probably need to move the OUTPUT before the increment to the date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  do until (date_of_service ge '01Jan2019'd);
    output;
    date_of_service = date_of_service + 90; 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2019 11:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557408#M155392</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-09T11:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557416#M155396</link>
      <description>&lt;P&gt;Good catch!&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 12:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557416#M155396</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-09T12:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557462#M155407</link>
      <description>&lt;P&gt;This didn't quite work - when I use just the first observation as have, this logic simply outputs the first observation without adjusting the date_of_service.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
do until (date_of_service ge '01Jan2019'd);
		output want;
	date_of_service = date_of_service + 90; 

end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I move the output statement to where it was before, it again outputs the first observation, but changes the date_of_service to 4/25.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
do until (date_of_service ge '01Jan2019'd);
	date_of_service = date_of_service + 90; 
	output want;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I put an output statement in &lt;EM&gt;both&lt;/EM&gt; places, it only outputs the first observation without adjusting the date_of_service.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have2;
do until (date_of_service ge '01Jan2019'd);
	output want;
	date_of_service = date_of_service + 90; 
	output want;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS Enterprise Guide, and submitting the code using the "Run Selection" option. I used the Generic SAS Editor to create the code. These are questions you had asked me to answer in another thread, so I figured I would post them here as well in case it is helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current version: 9.04.01M5P091317&lt;/P&gt;&lt;P&gt;Operating System: LIN X64&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 14:52:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557462#M155407</guid>
      <dc:creator>theponcer</dc:creator>
      <dc:date>2019-05-09T14:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Use a Do Loop to Adjust and Output Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557497#M155417</link>
      <description>&lt;P&gt;I had set options obs = 1 earlier, and never changed it back to max. Your code works, thanks a bunch!&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 16:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-a-Do-Loop-to-Adjust-and-Output-Data/m-p/557497#M155417</guid>
      <dc:creator>theponcer</dc:creator>
      <dc:date>2019-05-09T16:05:30Z</dc:date>
    </item>
  </channel>
</rss>

