<?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 How to separate a table in SAS based on rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858542#M339224</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to separate a table into 2 tables. For example, the original table has 1000 rows. I want to move the first 500 rows into table A and the last 500 rows into Table B. Does anyone know what code can perform this? Thank you for helping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Feb 2023 17:53:25 GMT</pubDate>
    <dc:creator>JQian</dc:creator>
    <dc:date>2023-02-13T17:53:25Z</dc:date>
    <item>
      <title>How to separate a table in SAS based on rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858542#M339224</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to separate a table into 2 tables. For example, the original table has 1000 rows. I want to move the first 500 rows into table A and the last 500 rows into Table B. Does anyone know what code can perform this? Thank you for helping.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 17:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858542#M339224</guid>
      <dc:creator>JQian</dc:creator>
      <dc:date>2023-02-13T17:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate a table in SAS based on rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858543#M339225</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one two;
    set have;
    if _n_&amp;lt;=500 then output one;
    else output two;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 17:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858543#M339225</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-13T17:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate a table in SAS based on rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858545#M339226</link>
      <description>&lt;P&gt;So you want to make two new datasets from one existing dataset?&amp;nbsp; Just name both target datasets on the DATA statement and then explicitly output the observations you want to each dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example to put the first 500 observations from HAVE into A and the rest into B you could do a data step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a b;
  set have;
  if _n_ &amp;lt;= 500 then output a;
  else output b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 17:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858545#M339226</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-13T17:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate a table in SAS based on rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858546#M339227</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the quick reply. What if I want row 2 to row 10 out to a new table? Is it&lt;/P&gt;&lt;P&gt;if (_n_&amp;nbsp; &amp;gt;= 2 and _n_ &amp;lt;= 10) then output newtable;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 18:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858546#M339227</guid>
      <dc:creator>JQian</dc:creator>
      <dc:date>2023-02-13T18:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate a table in SAS based on rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858548#M339228</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/401819"&gt;@JQian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the quick reply. What if I want row 2 to row 10 out to a new table? Is it&lt;/P&gt;
&lt;P&gt;if (_n_&amp;nbsp; &amp;gt;= 2 and _n_ &amp;lt;= 10) then output newtable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;or simplier:&lt;/P&gt;
&lt;P&gt;if 2 le _n_ le 10 then ...&lt;/P&gt;
&lt;P&gt;SAS will allow comparison more that way. I use the LE instead of &amp;lt;= because of some keyboard issues from many years ago.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or since we deal with integers&lt;/P&gt;
&lt;P&gt;if _n_ in (2:10) then ...&lt;/P&gt;
&lt;P&gt;The IN operator when comparing integers will accept the colon to indicate start and end of a range of values. This might be the preferred way if you wanted to do some skips and multiple ranges such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if _n_ in (2:10&amp;nbsp; 22:30&amp;nbsp; 41:66) then ...&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 18:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858548#M339228</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-13T18:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate a table in SAS based on rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858549#M339229</link>
      <description>&lt;P&gt;Should work.&amp;nbsp; If you just want to make one dataset you can also use the OBS= and FIRSTOBS= dataset option on the input dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (obs=10 firstobs=2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But doing the selection based on the &lt;STRONG&gt;order of the rows&lt;/STRONG&gt; is going to be much riskier than doing it based on &lt;STRONG&gt;some value in the data.&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 18:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-a-table-in-SAS-based-on-rows/m-p/858549#M339229</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-13T18:19:27Z</dc:date>
    </item>
  </channel>
</rss>

