<?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: Subquery in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717435#M80135</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16719"&gt;@Miracle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Dear All,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;How do we write the proc sql to retrieve only the observation rows when the same ID and the same date are present in both the data please?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Thanking you all in advance.&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why would you use SQL for such a simple request?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge dataset1 (in=in1)  dataset2(in=in2);
  by id date;
  if in1 and in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 07 Feb 2021 18:57:36 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-02-07T18:57:36Z</dc:date>
    <item>
      <title>Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717014#M80127</link>
      <description>&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Dear All,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;How do we write the proc sql to retrieve only the observation rows when the same ID and the same date are present in both the data please?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Thanking you all in advance.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 09:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717014#M80127</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2021-02-05T09:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717020#M80128</link>
      <description>&lt;P&gt;What do you mean by "both the data" ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please be more specific and show us your data.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 10:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717020#M80128</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-05T10:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717021#M80129</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select t1.*
  from t1
  where id in (select distinct id from t2)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace table and column names as needed&lt;/P&gt;
&lt;P&gt;Depending on dataset size, a DATA step with hash approach might perform better.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2021 10:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717021#M80129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-05T10:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717116#M80130</link>
      <description>&lt;P&gt;You can't use the IN operator for subsetting on two variables, but you can use the EXISTS operator:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select *
  from t1 as a
  where exists (select * from t2 where id=a.id and date=a.date);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Feb 2021 16:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717116#M80130</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-02-05T16:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717400#M80134</link>
      <description>&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;for&amp;nbsp;your response.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;I tried the proc sql as you advised but the code never stop running even for an entire day.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="andale mono,times" size="4"&gt;I wonder if it is due to the huge datasets i.e 10000k rows of data.&lt;BR /&gt;What other ways would you suggest please?&lt;BR /&gt;I am completely new to hash object so I don't understand how to write the syntax.&lt;BR /&gt;Thanking you in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 14:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717400#M80134</guid>
      <dc:creator>Miracle</dc:creator>
      <dc:date>2021-02-07T14:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717435#M80135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16719"&gt;@Miracle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Dear All,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;How do we write the proc sql to retrieve only the observation rows when the same ID and the same date are present in both the data please?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="andale mono,times" size="4"&gt;Thanking you all in advance.&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why would you use SQL for such a simple request?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge dataset1 (in=in1)  dataset2(in=in2);
  by id date;
  if in1 and in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Feb 2021 18:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717435#M80135</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-07T18:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Subquery</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717467#M80136</link>
      <description>&lt;P&gt;Then a hash approach should be tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which would look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set t1;
if _n_ = 1
then do;
  declare hash t2 (dataset:("t2");
  t2.definekey("id","date");
  t2.definedone();
end;
if t2.check() = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will work as long as the two variables * observations from t2 fit into memory.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2021 17:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Subquery/m-p/717467#M80136</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-08T17:27:15Z</dc:date>
    </item>
  </channel>
</rss>

