<?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 Loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535128#M6414</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data out;
/* it is never a good idea to overwrite the incoming dataset */
/* if something bad happens, all work up to now is lost */
set in;
do x = 1 to 20;/*Update the Range if fill Number Value goes beyond 20*/
  y = x - 1;
  if fill_Number = x
  then fill_Number = y;
  else fill_Number = x;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The way your code is written, fill_number will ALWAYS end up as 20.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2019 09:52:23 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-02-13T09:52:23Z</dc:date>
    <item>
      <title>DO Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535123#M6411</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create edit existing variable values with the help of DO LOOP in SAS Data Step. Below is the code i have written for the same. But when i am running this code I am not getting the expected result. What is going wrong in my code can you please suggest the corrections&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data IN;&lt;BR /&gt;set IN;&lt;BR /&gt;&amp;nbsp; do x = 1 to 20;/*Update the Range if fill Number Value goes beyond 20*/&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;y = x - 1;&lt;BR /&gt;if fill_Number = x then fill_Number = y;&lt;BR /&gt;else fill_Number = x;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please correct me if my code is wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 09:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535123#M6411</guid>
      <dc:creator>nishSAS</dc:creator>
      <dc:date>2019-02-13T09:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535125#M6413</link>
      <description>&lt;P&gt;What goes wrong? What do you expect and what results do you get?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 09:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535125#M6413</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-02-13T09:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535128#M6414</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data out;
/* it is never a good idea to overwrite the incoming dataset */
/* if something bad happens, all work up to now is lost */
set in;
do x = 1 to 20;/*Update the Range if fill Number Value goes beyond 20*/
  y = x - 1;
  if fill_Number = x
  then fill_Number = y;
  else fill_Number = x;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The way your code is written, fill_number will ALWAYS end up as 20.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 09:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535128#M6414</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-13T09:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535129#M6415</link>
      <description>&lt;P&gt;Post test data in the form of a datastep so we can see the inputs.&amp;nbsp; Show what output should be from that data.&amp;nbsp; We cannot guess from nothing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally a do loop iterates only within the individual observations, so in this case, for each observation the do loop will run 20 times, setting y to loop iteration -1, and when that equals x then the variable fill_number becomes the value in y, otherwise fill_number becomes x.&amp;nbsp; So from that logic you can see that the logic is never going to be right.&amp;nbsp; Take an example:&lt;/P&gt;
&lt;P&gt;loop 1: fill_number=0, x=1, y=x-1=0, fill_number set to 0&lt;/P&gt;
&lt;P&gt;loop 2: fill_number=0, x=2, y=x-1=1, fill_number set to 2&lt;/P&gt;
&lt;P&gt;loop 3: fill_number=2, x=3, y=x-1=2, fill_number set to 2&lt;/P&gt;
&lt;P&gt;loop 4:&amp;nbsp;fill_number=2, x=4, y=x-1=3, fill_number set to 3&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I can't see what you wanted to achieve i can't tell if that is right or "not working".&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 09:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535129#M6415</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-13T09:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535166#M6417</link>
      <description>&lt;P&gt;Thanks Kurt&lt;SPAN class="login-bold"&gt;&amp;nbsp;for your reply.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;I wanted to edit the fill_number column where column value start with 1 it should become 0, if value is 2 it should become 1 and so on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;When i am running below code my all fill_numver values are becoming 20. Which i don't want.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 12:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535166#M6417</guid>
      <dc:creator>nishSAS</dc:creator>
      <dc:date>2019-02-13T12:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: DO Loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535169#M6418</link>
      <description>&lt;P&gt;That means&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;fillnumber = fillnumber - 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For further help, post example data in a data step with datalines, and the expected output. See my footnotes for advice.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 12:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/DO-Loop/m-p/535169#M6418</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-02-13T12:37:06Z</dc:date>
    </item>
  </channel>
</rss>

