<?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: why repeated observations?? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297056#M62336</link>
    <description>&lt;P&gt;because it carries down from the information above...&lt;/P&gt;&lt;P&gt;You never told SAS to change the value...&lt;/P&gt;</description>
    <pubDate>Wed, 07 Sep 2016 20:04:14 GMT</pubDate>
    <dc:creator>AncaTilea</dc:creator>
    <dc:date>2016-09-07T20:04:14Z</dc:date>
    <item>
      <title>why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297050#M62330</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using below mentioned code but getting repeated observation and for first observation OUT variable has missing value...WHY??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new ;&lt;BR /&gt;do i=1 to 10;&lt;BR /&gt;if mod(i,2)=0 then out=i;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i&amp;nbsp;&amp;nbsp;&amp;nbsp; out&lt;BR /&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .&lt;BR /&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR /&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;BR /&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;BR /&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;BR /&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;BR /&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6&lt;BR /&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;BR /&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&lt;BR /&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 19:42:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297050#M62330</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2016-09-07T19:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297051#M62331</link>
      <description>Perhaps you need an else statement?</description>
      <pubDate>Wed, 07 Sep 2016 19:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297051#M62331</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-09-07T19:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297052#M62332</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;if you go through the do-loop, you will see how values get assigned to &lt;EM&gt;out:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;for i = 1, mod(i,2) = 0 is False, so &lt;EM&gt;out&lt;/EM&gt; = .;&lt;/P&gt;&lt;P&gt;output this record;&lt;/P&gt;&lt;P&gt;for i = 2, mod(i,2) = 0 is true, so &lt;EM&gt;out&lt;/EM&gt; = 2;&lt;/P&gt;&lt;P&gt;output this record;&lt;/P&gt;&lt;P&gt;for i = 3, mod(i,2) = 0 is False, so &lt;EM&gt;out&lt;/EM&gt; = 2;&lt;/P&gt;&lt;P&gt;output this record;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for i = 4, mod(i,2) = 0 is true, so &lt;EM&gt;out&lt;/EM&gt; = 4;&lt;/P&gt;&lt;P&gt;output this record;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you want&lt;EM&gt; out&lt;/EM&gt; to take a different value for the cases when mod(i,2) is false, then assign it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like,&lt;/P&gt;&lt;P&gt;if mod(i,2) = 0 then out = i;&lt;STRONG&gt;else out = .;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anca.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 19:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297052#M62332</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2016-09-07T19:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297053#M62333</link>
      <description>i simply want every second obs only.</description>
      <pubDate>Wed, 07 Sep 2016 19:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297053#M62333</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2016-09-07T19:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297054#M62334</link>
      <description>&lt;P&gt;Then do something like this:&lt;/P&gt;&lt;P&gt;data new ;&lt;BR /&gt;do i=1 to 10;&lt;BR /&gt;&lt;STRONG&gt;if mod(i,2)=0 then output;&lt;/STRONG&gt;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc print;run;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 19:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297054#M62334</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2016-09-07T19:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297055#M62335</link>
      <description>hi AncaTilea,&lt;BR /&gt;why for i=3 var OUT has a valur 2???</description>
      <pubDate>Wed, 07 Sep 2016 20:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297055#M62335</guid>
      <dc:creator>Rahul_SAS</dc:creator>
      <dc:date>2016-09-07T20:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297056#M62336</link>
      <description>&lt;P&gt;because it carries down from the information above...&lt;/P&gt;&lt;P&gt;You never told SAS to change the value...&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 20:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297056#M62336</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2016-09-07T20:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297057#M62337</link>
      <description>&lt;P&gt;Comment your code to help understand:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data new ; *Create a new dataset called new;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;do i=1 to 10; *Loop from 1 to 10;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if mod(i,2)=0 then out=i; *If number is even then assign counter, i, to variable out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output; *output, since no filters this would be all observations;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end; *end of loop;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run; *end of datastep;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Others have already posted the correct solution to your problem.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 20:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297057#M62337</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-07T20:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: why repeated observations??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297058#M62338</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2837"&gt;@Rahul_SAS&lt;/a&gt; wrote:&lt;BR /&gt;hi AncaTilea,&lt;BR /&gt;why for i=3 var OUT has a valur 2???&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This wouldn't happen a data step that was using an input data set. In that case it would reset to missing, because each new line sets all new variables to missing unless you have a retain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, in your case you have no input data set and are looping so it's really considered a single step and the values are retained until you reset them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2016 20:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/why-repeated-observations/m-p/297058#M62338</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-07T20:09:10Z</dc:date>
    </item>
  </channel>
</rss>

