<?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 Creating a do loop for multiple records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541769#M149647</link>
    <description>&lt;P&gt;Hi all.&amp;nbsp; I'm looking to create a variable that will flag weight-changes between weeks that are greater/ less than 8 pounds.&amp;nbsp; I think a do loop would be appropriate but I'm not exactly sure how because there are multiple entries per ID number...Here's the layout of my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Weight&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 130&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 135&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 128&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 149&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 151&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 146&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Mar 2019 02:19:08 GMT</pubDate>
    <dc:creator>jmmedina25</dc:creator>
    <dc:date>2019-03-10T02:19:08Z</dc:date>
    <item>
      <title>Creating a do loop for multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541769#M149647</link>
      <description>&lt;P&gt;Hi all.&amp;nbsp; I'm looking to create a variable that will flag weight-changes between weeks that are greater/ less than 8 pounds.&amp;nbsp; I think a do loop would be appropriate but I'm not exactly sure how because there are multiple entries per ID number...Here's the layout of my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Weight&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 130&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 135&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 128&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 149&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 151&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/21&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 146&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Mar 2019 02:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541769#M149647</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2019-03-10T02:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a do loop for multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541775#M149648</link>
      <description>The DATA step functions like a DO loop automatically, reading one observation then the next, then the next.  Try it this way:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by id;&lt;BR /&gt;change = dif(weight);&lt;BR /&gt;if first.id=0 then do;&lt;BR /&gt;  if change &amp;gt; 8 then flag ="+";&lt;BR /&gt;  else if change &amp;lt; -8 then flag ="-";&lt;BR /&gt;end;&lt;BR /&gt;run;</description>
      <pubDate>Sun, 10 Mar 2019 03:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541775#M149648</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-10T03:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a do loop for multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541780#M149652</link>
      <description>&lt;P&gt;Assuming that each record represents a week and that data is sorted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date $ Weight;
datalines;
1           6/6                130
1           6/13              135
1           6/21              118
2           6/6                149
2           6/13              151
2           6/21              146
;

data want;
do until(last.id);
    set have; by id;
    if not first.id then flag = abs(Weight-lastWeekWeight) &amp;gt; 8;
    output;
    lastWeekWeight = weight;
    end;
drop lastWeekWeight;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                        Obs    ID    Date    Weight    flag

                         1      1    6/6       130       .
                         2      1    6/13      135       0
                         3      1    6/21      118       1
                         4      2    6/6       149       .
                         5      2    6/13      151       0
                         6      2    6/21      146       0
&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Mar 2019 04:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/541780#M149652</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-10T04:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a do loop for multiple records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/542480#M149896</link>
      <description>&lt;P&gt;This code worked well; thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 16:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-do-loop-for-multiple-records/m-p/542480#M149896</guid>
      <dc:creator>jmmedina25</dc:creator>
      <dc:date>2019-03-12T16:14:58Z</dc:date>
    </item>
  </channel>
</rss>

