<?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 over the same observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423868#M104280</link>
    <description>&lt;P&gt;2 problems at least:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. The set statement will keep the latest values, so&amp;nbsp;&lt;FONT face="courier new,courier"&gt; .&amp;nbsp; .&amp;nbsp; 15&lt;/FONT&gt; for ID=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You can try to use UPDATE instead to ignore missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Maybe you can replace the set statement with (I never used UPDATE in a do loop so that's a test) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt; update HAVE(obs=0) HAVE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You dont need a loop really. Using the above statement without a do loop and testing end of group with function lag() would work for sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Another option is to store the non-missing values in different, retained, variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The test&amp;nbsp; &lt;FONT face="courier new,courier"&gt;year1=year2=year3&lt;/FONT&gt; should be&lt;FONT face="courier new,courier"&gt; year1=year2 and year2=year3&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Dec 2017 08:24:40 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-12-28T08:24:40Z</dc:date>
    <item>
      <title>do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423859#M104273</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am trying to do loop over the same observations in a big dataset. I have used existing codes in the communities , however, they did not work.&lt;/P&gt;&lt;P&gt;here is a part of dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Id&amp;nbsp;&amp;nbsp; year1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year3&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; . &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I want to apply some conditions , for example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;do until (last.Id);&lt;BR /&gt;set have ;&lt;BR /&gt;by id;&lt;BR /&gt;if year1=year2=year3 then delete;end; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;what is the problem with this code?&lt;/P&gt;&lt;P&gt;your help will be appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 07:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423859#M104273</guid>
      <dc:creator>ali_far</dc:creator>
      <dc:date>2017-12-28T07:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423868#M104280</link>
      <description>&lt;P&gt;2 problems at least:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. The set statement will keep the latest values, so&amp;nbsp;&lt;FONT face="courier new,courier"&gt; .&amp;nbsp; .&amp;nbsp; 15&lt;/FONT&gt; for ID=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You can try to use UPDATE instead to ignore missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Maybe you can replace the set statement with (I never used UPDATE in a do loop so that's a test) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt; update HAVE(obs=0) HAVE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You dont need a loop really. Using the above statement without a do loop and testing end of group with function lag() would work for sure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Another option is to store the non-missing values in different, retained, variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The test&amp;nbsp; &lt;FONT face="courier new,courier"&gt;year1=year2=year3&lt;/FONT&gt; should be&lt;FONT face="courier new,courier"&gt; year1=year2 and year2=year3&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 08:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423868#M104280</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-12-28T08:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423876#M104282</link>
      <description>&lt;P&gt;What do you want your desired result to look like?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 10:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423876#M104282</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-28T10:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423878#M104283</link>
      <description>&lt;P&gt;Reconsider your data model. Having the years in the columns is why you have this challenge. A normalized table would have three columns: id, year and value. This would make any logic or reporting much easier. And just imagine what would be the consequence if you&amp;nbsp; have to add another year. Look at proc transpose or diy a datastep.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 11:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423878#M104283</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2017-12-28T11:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423879#M104284</link>
      <description>&lt;P&gt;If the intent is to keep ID=1, but delete ID=2, while getting all the data onto a single observation for each ID, you could try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;update have (obs=0) have;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if year1=year2=year3 then delete;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not the intent, you will need to spell it out.&amp;nbsp; We can't really figure out why the code doesn't work if we don't know what it is supposed to accomplish.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2017 11:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/423879#M104284</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-28T11:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/424000#M104342</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks, you are right. I have restructured the data set. Now it is even easier for the further analysis.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Fri, 29 Dec 2017 06:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/424000#M104342</guid>
      <dc:creator>ali_far</dc:creator>
      <dc:date>2017-12-29T06:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: do loop over the same observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/424001#M104343</link>
      <description>Thanks, It is useful. However I decided to restructure the data set for further analysis</description>
      <pubDate>Fri, 29 Dec 2017 06:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-over-the-same-observations/m-p/424001#M104343</guid>
      <dc:creator>ali_far</dc:creator>
      <dc:date>2017-12-29T06:44:05Z</dc:date>
    </item>
  </channel>
</rss>

