<?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 split a table into two different tables based on another table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53432#M14760</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a table called table1.&amp;nbsp; I want to subset table2 into two different tables based on if the values in table1 match table2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;table1&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table2&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to split table2 into table3 and table4&lt;/P&gt;&lt;P&gt;If table2 has an ID that matches table1 then move that row into table3&lt;/P&gt;&lt;P&gt;If table2 does not match any IDs in table1 put those rows in table4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table3&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table4&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this possible with a merge in one data step?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Feb 2012 16:38:53 GMT</pubDate>
    <dc:creator>jerry898969</dc:creator>
    <dc:date>2012-02-14T16:38:53Z</dc:date>
    <item>
      <title>How to split a table into two different tables based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53432#M14760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a table called table1.&amp;nbsp; I want to subset table2 into two different tables based on if the values in table1 match table2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;table1&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table2&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to split table2 into table3 and table4&lt;/P&gt;&lt;P&gt;If table2 has an ID that matches table1 then move that row into table3&lt;/P&gt;&lt;P&gt;If table2 does not match any IDs in table1 put those rows in table4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table3&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table4&lt;/P&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this possible with a merge in one data step?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 16:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53432#M14760</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2012-02-14T16:38:53Z</dc:date>
    </item>
    <item>
      <title>How to split a table into two different tables based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53433#M14761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This can be accomplished quite simple with a data step MERGE using IN= data set options, combined with conditional OUTPUT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 16:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53433#M14761</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-02-14T16:42:58Z</dc:date>
    </item>
    <item>
      <title>How to split a table into two different tables based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53434#M14762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your tables are already sorted by id you could use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;8&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input ID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table3 table4;&lt;/P&gt;&lt;P&gt;&amp;nbsp; merge table1 (keep=id in=one) table2 (in=two);&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if one and two then output table3;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if two then output table4;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 16:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53434#M14762</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-02-14T16:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a table into two different tables based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53435#M14763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table1;&lt;/P&gt;&lt;P&gt;input ID;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data table2;&lt;/P&gt;&lt;P&gt;input ID;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want1 want2;&lt;/P&gt;&lt;P&gt;merge table2 (in=t2) table1(in=t1);&lt;/P&gt;&lt;P&gt;by id;&lt;/P&gt;&lt;P&gt;if t1 and t2 then output want1;&lt;/P&gt;&lt;P&gt;if t2 and not t1 then output want2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note, you probably want to only keep the variables form table2 by using the data step options: data want1 (keep=) want2 (keep=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit: Art just has offered a great solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 16:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53435#M14763</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-02-14T16:46:46Z</dc:date>
    </item>
    <item>
      <title>How to split a table into two different tables based on another table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53436#M14764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you for the help that did exactly what I wanted.&amp;nbsp; Thank you to everyone for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2012 16:53:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-split-a-table-into-two-different-tables-based-on-another/m-p/53436#M14764</guid>
      <dc:creator>jerry898969</dc:creator>
      <dc:date>2012-02-14T16:53:41Z</dc:date>
    </item>
  </channel>
</rss>

