<?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: How to use Do statement ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259185#M50091</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/71899"&gt;@Beto16﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would&amp;nbsp;this work for you?&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt;input Machine $ Date :mmddyy. Load Use;&lt;BR /&gt;format Date mmddyy8.;&lt;BR /&gt;cards;&lt;BR /&gt;A1 02/03/16 160 31&lt;BR /&gt;A1 02/18/16 40 83&lt;BR /&gt;A1 02/25/17 80 0&lt;BR /&gt;A2 02/03/16 150 80&lt;BR /&gt;A2 02/18/16 70 70&lt;BR /&gt;A2 02/25/17 42 43&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by machine date;&lt;BR /&gt;if first.machine then load1=load;&lt;BR /&gt;else if use&amp;gt;load&amp;gt;. then load=load1;&lt;BR /&gt;retain load1;&lt;BR /&gt;drop load1;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;This code doesn't use a DO statement, but unlike your suggested code it involves a condition with "greater than."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's good that you posted an example, but it would be even better if, in addition, you stated the rule ("if ... greater than ..., then ...") in &lt;EM&gt;general&lt;/EM&gt; terms (e.g. "... then use the load value of the first observation of the machine" or "... then use the load value from the previous observation of the same machine" ...).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Modified the test data for machine A2 a bit to make it more significant.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2016 22:16:41 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-03-25T22:16:41Z</dc:date>
    <item>
      <title>How to use Do statement ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259163#M50088</link>
      <description>Hi I have a table that looks like this&lt;BR /&gt;&lt;BR /&gt;Machine. Date. Load. Use&lt;BR /&gt;A1. 02/03/16. 160. 31&lt;BR /&gt;A1. 02/18/16. 40. 83&lt;BR /&gt;A1. 02\25/17. 80. 0&lt;BR /&gt;The first row is perfect. What I need is is 2nd row amt 83 is greater than the load of 40 than use the load amt of first row 160.... if it's less than use 40...&lt;BR /&gt;Here is what I need&lt;BR /&gt;&lt;BR /&gt;Machine. Date. Load. Use&lt;BR /&gt;A1. 02/03/16. 160. 31&lt;BR /&gt;A1. 02/18/16. 160 83&lt;BR /&gt;A1. 02\25/17. 80. 0&lt;BR /&gt;&lt;BR /&gt;this is what I get&lt;BR /&gt;Machine. Date. Load. Use&lt;BR /&gt;A1. 02/03/16. 160. 31&lt;BR /&gt;A1. 02/18/16. 160 31&lt;BR /&gt;A1. 02\25/17. 40 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data table_lag;&lt;BR /&gt;Set table;&lt;BR /&gt;By machine date;&lt;BR /&gt;Load_Lag=lag (load);&lt;BR /&gt;Use_lag=lag (use);&lt;BR /&gt;If first.machine&lt;BR /&gt;then&lt;BR /&gt;&lt;BR /&gt;Do;&lt;BR /&gt;Load_Lag=lag load;&lt;BR /&gt;Use_lag=lag use;&lt;BR /&gt;End;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Mar 2016 21:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259163#M50088</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-03-25T21:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Do statement ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259185#M50091</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/71899"&gt;@Beto16﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would&amp;nbsp;this work for you?&lt;/P&gt;
&lt;PRE&gt;data have;&lt;BR /&gt;input Machine $ Date :mmddyy. Load Use;&lt;BR /&gt;format Date mmddyy8.;&lt;BR /&gt;cards;&lt;BR /&gt;A1 02/03/16 160 31&lt;BR /&gt;A1 02/18/16 40 83&lt;BR /&gt;A1 02/25/17 80 0&lt;BR /&gt;A2 02/03/16 150 80&lt;BR /&gt;A2 02/18/16 70 70&lt;BR /&gt;A2 02/25/17 42 43&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by machine date;&lt;BR /&gt;if first.machine then load1=load;&lt;BR /&gt;else if use&amp;gt;load&amp;gt;. then load=load1;&lt;BR /&gt;retain load1;&lt;BR /&gt;drop load1;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;This code doesn't use a DO statement, but unlike your suggested code it involves a condition with "greater than."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's good that you posted an example, but it would be even better if, in addition, you stated the rule ("if ... greater than ..., then ...") in &lt;EM&gt;general&lt;/EM&gt; terms (e.g. "... then use the load value of the first observation of the machine" or "... then use the load value from the previous observation of the same machine" ...).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: Modified the test data for machine A2 a bit to make it more significant.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 22:16:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259185#M50091</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-25T22:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Do statement ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259261#M50127</link>
      <description>Thank you ..I will test it</description>
      <pubDate>Sun, 27 Mar 2016 16:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Do-statement/m-p/259261#M50127</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-03-27T16:18:06Z</dc:date>
    </item>
  </channel>
</rss>

