<?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 qustion about do loop in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57495#M16041</link>
    <description>I need someone to help me to explain the following process:&lt;BR /&gt;
&lt;BR /&gt;
data sample:&lt;BR /&gt;
&lt;BR /&gt;
flag      num_a      num_b &lt;BR /&gt;
1               0            3&lt;BR /&gt;
1               0            3&lt;BR /&gt;
1               0            3&lt;BR /&gt;
2               4            4&lt;BR /&gt;
&lt;BR /&gt;
The task is to let num_a = num_b,  then set num_b = 0, if flag equals 1.&lt;BR /&gt;
&lt;BR /&gt;
expected result:&lt;BR /&gt;
&lt;BR /&gt;
condition  num_a    num_b&lt;BR /&gt;
1                3            0&lt;BR /&gt;
1                3            0&lt;BR /&gt;
1                3            0&lt;BR /&gt;
2                4            4&lt;BR /&gt;
&lt;BR /&gt;
I use a do-end loop to execute it, and coding like this:&lt;BR /&gt;
&lt;BR /&gt;
 if condition = 1 then do;&lt;BR /&gt;
  num_a = num_b;&lt;BR /&gt;
  num_b = 0; &lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
but it doesn't work &lt;BR /&gt;
The first column is converted correctly, but the rest records are all set to 0. It look like it execue num_b=0 first then execute num_a=num_b;&lt;BR /&gt;
&lt;BR /&gt;
the result ended up like this:&lt;BR /&gt;
&lt;BR /&gt;
condition num_a num_b&lt;BR /&gt;
  1             3        0&lt;BR /&gt;
  1             0        0&lt;BR /&gt;
  1             0        0&lt;BR /&gt;
  2             4        4&lt;BR /&gt;
&lt;BR /&gt;
Even I seperated the do loop steps it gets the same results:&lt;BR /&gt;
&lt;BR /&gt;
revised code:&lt;BR /&gt;
&lt;BR /&gt;
 if condition = 1 then do;&lt;BR /&gt;
  num_a = num_b;&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
 if condition = 1 then do;&lt;BR /&gt;
 num_b = 0; &lt;BR /&gt;
 end;&lt;BR /&gt;
&lt;BR /&gt;
Anyone can explain this to me?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,</description>
    <pubDate>Tue, 28 Oct 2008 17:50:49 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-28T17:50:49Z</dc:date>
    <item>
      <title>qustion about do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57495#M16041</link>
      <description>I need someone to help me to explain the following process:&lt;BR /&gt;
&lt;BR /&gt;
data sample:&lt;BR /&gt;
&lt;BR /&gt;
flag      num_a      num_b &lt;BR /&gt;
1               0            3&lt;BR /&gt;
1               0            3&lt;BR /&gt;
1               0            3&lt;BR /&gt;
2               4            4&lt;BR /&gt;
&lt;BR /&gt;
The task is to let num_a = num_b,  then set num_b = 0, if flag equals 1.&lt;BR /&gt;
&lt;BR /&gt;
expected result:&lt;BR /&gt;
&lt;BR /&gt;
condition  num_a    num_b&lt;BR /&gt;
1                3            0&lt;BR /&gt;
1                3            0&lt;BR /&gt;
1                3            0&lt;BR /&gt;
2                4            4&lt;BR /&gt;
&lt;BR /&gt;
I use a do-end loop to execute it, and coding like this:&lt;BR /&gt;
&lt;BR /&gt;
 if condition = 1 then do;&lt;BR /&gt;
  num_a = num_b;&lt;BR /&gt;
  num_b = 0; &lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
but it doesn't work &lt;BR /&gt;
The first column is converted correctly, but the rest records are all set to 0. It look like it execue num_b=0 first then execute num_a=num_b;&lt;BR /&gt;
&lt;BR /&gt;
the result ended up like this:&lt;BR /&gt;
&lt;BR /&gt;
condition num_a num_b&lt;BR /&gt;
  1             3        0&lt;BR /&gt;
  1             0        0&lt;BR /&gt;
  1             0        0&lt;BR /&gt;
  2             4        4&lt;BR /&gt;
&lt;BR /&gt;
Even I seperated the do loop steps it gets the same results:&lt;BR /&gt;
&lt;BR /&gt;
revised code:&lt;BR /&gt;
&lt;BR /&gt;
 if condition = 1 then do;&lt;BR /&gt;
  num_a = num_b;&lt;BR /&gt;
  end;&lt;BR /&gt;
&lt;BR /&gt;
 if condition = 1 then do;&lt;BR /&gt;
 num_b = 0; &lt;BR /&gt;
 end;&lt;BR /&gt;
&lt;BR /&gt;
Anyone can explain this to me?&lt;BR /&gt;
&lt;BR /&gt;
Thanks,</description>
      <pubDate>Tue, 28 Oct 2008 17:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57495#M16041</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-28T17:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: qustion about do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57496#M16042</link>
      <description>I suggest you run your code in a SAS DATA step, either using DATALINES;  with an INPUT statement, or with a SET (from a previous SAS data member).  Then add two statements, as shown below, around your code to generate diagnostics:&lt;BR /&gt;
&lt;BR /&gt;
DATA _NULL_;&lt;BR /&gt;
SET &lt;YOUR_SAMPLE_INPUT_DATA_GOES_HERE&gt;;&lt;BR /&gt;
PUTLOG "&amp;gt;BEFORE&amp;gt;" / _ALL_;&lt;BR /&gt;
* your code goes here. ;&lt;BR /&gt;
PUTLOG "&amp;gt;AFTER&amp;gt;" / _ALL_;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
With the additional DATA step processing diagnostics, I would expect you can see the processing results and reasoning with your own code.  If the problem still exists, paste the entire SASLOG output into your post for the forum subscribers to respond with feedback.  It's important that you share your exact DATA step code, using COPY and PASTE for accuracy and purpose.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/YOUR_SAMPLE_INPUT_DATA_GOES_HERE&gt;</description>
      <pubDate>Tue, 28 Oct 2008 21:25:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57496#M16042</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-10-28T21:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: qustion about do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57497#M16043</link>
      <description>Hi dust,&lt;BR /&gt;
          The below mentioned code will give you the your desired result.&lt;BR /&gt;
if flag = 1 then do;&lt;BR /&gt;
num_a = num_b;&lt;BR /&gt;
num_b = 0; &lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
By running the above code I am getting the below result&lt;BR /&gt;
flag num_a num_b&lt;BR /&gt;
1 3 0&lt;BR /&gt;
1 3 0&lt;BR /&gt;
1 3 0&lt;BR /&gt;
2 4 4&lt;BR /&gt;
&lt;BR /&gt;
not like what you have mentioned.once agin verify the above code,it will give you the your desired result.</description>
      <pubDate>Wed, 29 Oct 2008 06:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57497#M16043</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-29T06:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: qustion about do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57498#M16044</link>
      <description>Thanks all for your kindly response. &lt;BR /&gt;
Sivas, that's eactly what troubles me. This piece of example is from an old program which had been runing for years. Someone found the problem with the output data recently, and I checked the process and identified the issue. It should work as you pointed out, but it didn't. Could that be possible it is caused by a SAS version problem? I have reasons to believe the code used to worked well. (Of course I can't be 100% sure.) An update SAS version in our unix environment last year may caused the problem. Again, just my guess.&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for your help</description>
      <pubDate>Wed, 29 Oct 2008 15:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57498#M16044</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-29T15:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: qustion about do loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57499#M16045</link>
      <description>As was suggested, share your "executed" SAS code with additional diagnostics in a SASLOG (pasted in your post), otherwise feedback cannot be accurately provided, based on the lack of actual SAS output.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 30 Oct 2008 02:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/qustion-about-do-loop/m-p/57499#M16045</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-10-30T02:28:36Z</dc:date>
    </item>
  </channel>
</rss>

