<?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: Selecting every other row in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30997#M5931</link>
    <description>MOD&lt;BR /&gt;
Returns the remainder from the division of the first argument by the second argument, fuzzed to avoid most unexpected floating-point results &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data classEven;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   if mod(_n_,2) eq 0;&lt;BR /&gt;
   obs = _n_;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print; &lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
data classEven;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   where mod(monotonic(),2) eq 0;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Wed, 16 Mar 2011 15:16:04 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2011-03-16T15:16:04Z</dc:date>
    <item>
      <title>Selecting every other row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30996#M5930</link>
      <description>This seems like it should have a fairly easy solution, but I have not been able to find it. I want to keep every 2nd row in a data set I have, deleting each odd numbered row. The only way I can think to do this is to create an index spanning the whole set, then delete based on the index, but I'm unsure how to do that. &lt;BR /&gt;
&lt;BR /&gt;
Any help would be appreciated.</description>
      <pubDate>Wed, 16 Mar 2011 15:06:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30996#M5930</guid>
      <dc:creator>Sroy9</dc:creator>
      <dc:date>2011-03-16T15:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting every other row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30997#M5931</link>
      <description>MOD&lt;BR /&gt;
Returns the remainder from the division of the first argument by the second argument, fuzzed to avoid most unexpected floating-point results &lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data classEven;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   if mod(_n_,2) eq 0;&lt;BR /&gt;
   obs = _n_;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print; &lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
data classEven;&lt;BR /&gt;
   set sashelp.class;&lt;BR /&gt;
   where mod(monotonic(),2) eq 0;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 16 Mar 2011 15:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30997#M5931</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-03-16T15:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting every other row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30998#M5932</link>
      <description>Hi:&lt;BR /&gt;
  My usual warning about monotonic(), which may work in this case, but is not guaranteed to work in all cases... Any warning like this gives me something to worry about:&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/15/138.html" target="_blank"&gt;http://support.sas.com/kb/15/138.html&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
  A simple alternative (assuming that you are not doing anything other than a simple read and write with the data step program, so that _n_ will correspond to the number of obs in the data set).&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data classSimple;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
  orig_obs = _n_;&lt;BR /&gt;
  if mod(_n_,2) eq 0 then output;&lt;BR /&gt;
run;&lt;BR /&gt;
                                &lt;BR /&gt;
proc print data=classSimple;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 16 Mar 2011 15:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30998#M5932</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-03-16T15:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting every other row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30999#M5933</link>
      <description>Thanks, I didn't know the row indexes could be referenced as _n_. Works perfectly now.</description>
      <pubDate>Wed, 16 Mar 2011 15:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/30999#M5933</guid>
      <dc:creator>Sroy9</dc:creator>
      <dc:date>2011-03-16T15:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting every other row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/31000#M5934</link>
      <description>_N_ is not the row index.  It is the data step iteration counter.  In this simple situation they are equal, but not always.</description>
      <pubDate>Wed, 16 Mar 2011 15:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/31000#M5934</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-03-16T15:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting every other row in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/31001#M5935</link>
      <description>Hi:&lt;BR /&gt;
  Data _NULL_ is correct. _N_ is &lt;B&gt;&lt;U&gt;not&lt;/U&gt;&lt;/B&gt;&lt;U&gt;&lt;/U&gt; a row index -- it is a count of loops through the data step program. Which is why I qualified what I said about using _N_ -- that as long as you were doing a simple read/write in your program you could use _N_. Because in that instance, _N_ will correspond to each observation, assuming that each observation is read with 1 loop of the DATA step program. &lt;BR /&gt;
 &lt;BR /&gt;
  You could write DATA step programs to read more than one observation in a single loop of the program -- in which case, _N_ would cease to be a possibility. But in your case, assuming you have explained the problem as your program works -- with a simple read/write situation -- and you are only reading 1 observation for every loop through the program, then you can use _N_ as shown.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 16 Mar 2011 15:59:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-every-other-row-in-a-dataset/m-p/31001#M5935</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-03-16T15:59:15Z</dc:date>
    </item>
  </channel>
</rss>

