<?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 PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509418#M136956</link>
    <description>Hi&lt;BR /&gt;&lt;BR /&gt;I just want to clarify in what order given steps will be executed in proc sql.&lt;BR /&gt;&lt;BR /&gt;Let us say we have table A 91 000 000 rows and table B with 2 900 000.&lt;BR /&gt;&lt;BR /&gt;We want to left join these table on id and using where statement filter out based on a condition.&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test as&lt;BR /&gt;select a.*&lt;BR /&gt;from a&lt;BR /&gt;left join b on a.id=b.id&lt;BR /&gt;where a.status=1;&lt;BR /&gt;&lt;BR /&gt;Will tables be joined first and then filter in where close will be applied?&lt;BR /&gt;&lt;BR /&gt;Or are we reading row by row from table a, checking condition and if it met run left join?&lt;BR /&gt;&lt;BR /&gt;What is the best way to join such a big tables?</description>
    <pubDate>Thu, 01 Nov 2018 06:42:43 GMT</pubDate>
    <dc:creator>irinaia</dc:creator>
    <dc:date>2018-11-01T06:42:43Z</dc:date>
    <item>
      <title>PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509418#M136956</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I just want to clarify in what order given steps will be executed in proc sql.&lt;BR /&gt;&lt;BR /&gt;Let us say we have table A 91 000 000 rows and table B with 2 900 000.&lt;BR /&gt;&lt;BR /&gt;We want to left join these table on id and using where statement filter out based on a condition.&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test as&lt;BR /&gt;select a.*&lt;BR /&gt;from a&lt;BR /&gt;left join b on a.id=b.id&lt;BR /&gt;where a.status=1;&lt;BR /&gt;&lt;BR /&gt;Will tables be joined first and then filter in where close will be applied?&lt;BR /&gt;&lt;BR /&gt;Or are we reading row by row from table a, checking condition and if it met run left join?&lt;BR /&gt;&lt;BR /&gt;What is the best way to join such a big tables?</description>
      <pubDate>Thu, 01 Nov 2018 06:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509418#M136956</guid>
      <dc:creator>irinaia</dc:creator>
      <dc:date>2018-11-01T06:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509423#M136957</link>
      <description>&lt;P&gt;Please use the code window, its the {i} for posting code.&amp;nbsp; Your code doesn't make sense, you never use table b, so the statement is:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table test as
  select a.*
  from a a
  where status=1;
quit;
&lt;/PRE&gt;
&lt;P&gt;That being said, its quite a lot of observations, so you may get better performance using a datastep (assumes they are sorted):&lt;/P&gt;
&lt;PRE&gt;data test;
  merge a (where=(status=1) in=a)
        b (in=b);
  by id;
  if a;
run;&lt;/PRE&gt;
&lt;P&gt;Oh, and that where a.status will be executed after merge, you can subquery, eg.:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table test as
  select a.*
  from (select * from a where status=1) a&lt;BR /&gt;  left join b b&lt;BR /&gt;  on   a.id=b.id;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Nov 2018 08:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509423#M136957</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-01T08:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509426#M136960</link>
      <description>&lt;P&gt;Hi&amp;nbsp; ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is no memory concern , kindly use&amp;nbsp; hash object to join ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is a sample code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input id status;
cards;
1 1
2 1
3 .
4 1
5 1
6 1
;
run;


data b;
input id;
cards;
1
2
3
5
;
run;

DATA WANT;
IF _N_=1 THEN DO;
DECLARE HASh H(DATASET:'B');
 H.DEFINEKEY('ID');
 H.DEFINEDATA('ID');
 H.DEFINEDONE();
END;
 DO UNTIL(LR);
  SET A END=LR;
  WHERE STATUS=1;
  ARRAY ARR ID;
  DO OVER ARR;
   r=H.find(key:arr);
   if r ge 0 THEN OUTPUT;
  END;
 END;
 drop r;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Nov 2018 09:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509426#M136960</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-11-01T09:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509449#M136966</link>
      <description>&lt;P&gt;This is not a real code and the aim of it was just to show in what order statements are written.&lt;BR /&gt;&lt;BR /&gt;What i want to know is in what order queries like this will be executed.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select a.*, b.status
from a
left join b b
on a.id=b.id;
where current=1 and sum&amp;gt;0
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Will SAS read row by row from database, check if it satisfy the condition in where close and then go through another table ,b-table, check if the row with same id exist there and then join.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 11:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509449#M136966</guid>
      <dc:creator>irinaia</dc:creator>
      <dc:date>2018-11-01T11:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509460#M136969</link>
      <description>&lt;P&gt;So it is being executed on a database now?&amp;nbsp; I am afraid I cannot hypothetical questions.&amp;nbsp; If the SQL is being run within SAS then you can see the process using&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql _tree _method;&lt;/PRE&gt;
&lt;P&gt;Options, that may help you.&amp;nbsp; If its run on a database then you would need to check the SQL on the database itself.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 11:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509460#M136969</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-01T11:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509477#M136972</link>
      <description>Do you mean that the whole sql querie against RDBMS will be always executed on SQL side and SAS will only get returned the final result or it will return row by row? I just want to understand where query will be executed, in what order and so on.</description>
      <pubDate>Thu, 01 Nov 2018 12:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509477#M136972</guid>
      <dc:creator>irinaia</dc:creator>
      <dc:date>2018-11-01T12:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509496#M136979</link>
      <description>&lt;P&gt;if the data in rdbms, which ebdms is it?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 13:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509496#M136979</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-01T13:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509499#M136980</link>
      <description>&lt;P&gt;MS SQL Server&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 13:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509499#M136980</guid>
      <dc:creator>irinaia</dc:creator>
      <dc:date>2018-11-01T13:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509502#M136982</link>
      <description>&lt;P&gt;Again, that depends on several different factors.&amp;nbsp; If you use explicit pass-through, then all the SQL in there gets passed to the database for execution and results returned.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your using a libname setup like:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#p1a9wh7qwv6vc9n18arz94i379q0.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/acreldb/65247/HTML/default/viewer.htm#p1a9wh7qwv6vc9n18arz94i379q0.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then the SQL is generated internally and sent to the DB for results to be passed back.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 13:25:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509502#M136982</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-01T13:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509505#M136983</link>
      <description>&lt;P&gt;you can run showplan and you should try to run in sql server side itself. check whether your datasets have indexes. if you have access to sql server maangement studio and then you can see execution plan. it gives a very detailed info of how much time your query takes and which step it is taking time.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 13:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/509505#M136983</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-11-01T13:29:39Z</dc:date>
    </item>
  </channel>
</rss>

