<?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: Sorting Leaving, Entering and Staying observations from table T0 to table T1 based on two id col in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458201#M116254</link>
    <description>&lt;P&gt;This should select the sets of id variables you need.&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table uniquet0 as
   select * from (select distinct id1, id2 from t0)
   except
   select * from (select distinct id1, id2 from t1);

   create table uniquet1 as
   select * from (select distinct id1, id2 from t1)
   except
   select * from (select distinct id1, id2 from t0);

   create table common as
   select * from (select distinct id1, id2 from t1)
   intersect
   select * from (select distinct id1, id2 from t0);

quit;

&lt;/PRE&gt;
&lt;P&gt;Each of these would likely need to be joined (left or right likely) with the other data to bring in other variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 27 Apr 2018 17:55:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-04-27T17:55:32Z</dc:date>
    <item>
      <title>Sorting Leaving, Entering and Staying observations from table T0 to table T1 based on two id columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458197#M116253</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two big tables, table T0 and table T1 that represents observations for two different months. I want to create three new tables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-one that has unique observations id for T0;&lt;/P&gt;&lt;P&gt;-one that has same &lt;SPAN&gt;observations&amp;nbsp;&lt;/SPAN&gt;id for T0 and T1;&lt;/P&gt;&lt;P&gt;-one that has unique &lt;SPAN&gt;observations&amp;nbsp;&lt;/SPAN&gt;id for T1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unique id is based on two columns: id1 &amp;amp; id2. I would prefer using proc sql for this as well. Is there a way for me to sort this without using left join and without merging id1 and id2 in a new variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 17:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458197#M116253</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2018-04-27T17:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Leaving, Entering and Staying observations from table T0 to table T1 based on two id col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458201#M116254</link>
      <description>&lt;P&gt;This should select the sets of id variables you need.&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table uniquet0 as
   select * from (select distinct id1, id2 from t0)
   except
   select * from (select distinct id1, id2 from t1);

   create table uniquet1 as
   select * from (select distinct id1, id2 from t1)
   except
   select * from (select distinct id1, id2 from t0);

   create table common as
   select * from (select distinct id1, id2 from t1)
   intersect
   select * from (select distinct id1, id2 from t0);

quit;

&lt;/PRE&gt;
&lt;P&gt;Each of these would likely need to be joined (left or right likely) with the other data to bring in other variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 17:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458201#M116254</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-27T17:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Leaving, Entering and Staying observations from table T0 to table T1 based on two id col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458204#M116255</link>
      <description>Thank you, yes this works to get the sets of id that I need . I was trying to avoid doing it in two steps and Left joining afterwards. Is there a way to do this more efficiently in one step? Thank you very much for your time.</description>
      <pubDate>Fri, 27 Apr 2018 18:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458204#M116255</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2018-04-27T18:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Leaving, Entering and Staying observations from table T0 to table T1 based on two id col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458208#M116256</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150111"&gt;@x2PSx&lt;/a&gt; wrote:&lt;BR /&gt;Thank you, yes this works to get the sets of id that I need . I was trying to avoid doing it in two steps and Left joining afterwards. Is there a way to do this more efficiently in one step? Thank you very much for your time.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Without data and knowing what comes from each set then it is very hard to tell what might be needed.&lt;/P&gt;
&lt;P&gt;Do note that the core of any of those queries could be used such as:&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   create table wat as
   selct b.* 
   from (
      select * from (select distinct id1, id2 from t0)
      except
      select * from (select distinct id1, id2 from t1)
      ) as a
      left join t0 as b
      on a.id1=b.id1 and a.id2=b.id2
   ;

quit;&lt;/PRE&gt;
&lt;P&gt;But if you need variables from both t0 and t1 then there will be more code involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the concern over the left join? When it is appropriate tool use it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might provide some short examples of the two data sets and the desired final output.&lt;/P&gt;
&lt;P&gt;I can see a possibility of a data step but that would require sorting both data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Efficiency" comes in a number flavors: easy to write/maintain code, disk storage space, cpu run times are a few&amp;nbsp;for example. Single complex queries may have fewer typed characters but may&amp;nbsp;&amp;nbsp;be harder write initially (hence your question)&amp;nbsp;and maintain when changes occur. And the more complex a single query gets the longer it is likely to run.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Apr 2018 18:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-Leaving-Entering-and-Staying-observations-from-table-T0/m-p/458208#M116256</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-27T18:19:54Z</dc:date>
    </item>
  </channel>
</rss>

