<?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: Converting SQL Server code to SAS DI 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/850024#M335983</link>
    <description>&lt;P&gt;I think the key element here is:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does the code suppose to do that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Usually&lt;SPAN&gt;&amp;nbsp;cartesian joins is not what you want. But on the other hand, the SQLS and SAS code looks "identical"...?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I see two ways forward here:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Go back to the requirements&amp;nbsp;to understand what output is to produce, and then building it with an ETL flow from scratch, instead of copy/paste code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Look into your data, compare your SAS work tables with corresponding&amp;nbsp;ones in SQLS&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Dec 2022 07:23:05 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2022-12-16T07:23:05Z</dc:date>
    <item>
      <title>Converting SQL Server code to SAS DI 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/849855#M335937</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Basically I am converting SQLserver code to SAS in SAS 9.4 DI studio and I am getting below error. It will be great helpful if any one can suggest better approach to redesign the SAS code in Proc SQL/SAS Datastep.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ERROR:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;BR /&gt;ERROR: Sort execution failure.&lt;/P&gt;&lt;P&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;BR /&gt;1036 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: Due to ERROR(s) above, SAS set option OBS=0, enabling syntax check mode. This prevents execution of subsequent data modification statements.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 33:46.96&lt;BR /&gt;cpu time 1:10:16.57&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SQL Server code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;create view [dbo].&amp;lt;view_name&amp;gt; as&lt;BR /&gt;select *&lt;BR /&gt;from [Schema].[dbo].[Fact_TableA] dd&lt;BR /&gt;LEFT JOIN [Schema].[dbo].[Fact_TableB] gr on (dd.account_id = gr.account_id)&lt;BR /&gt;LEFT JOIN [Schema].[dbo].[Fact_TableC] gh on (dd.account_id = gh.account_id)&lt;BR /&gt;LEFT JOIN [Schema].[dbo].[Fact_TableD] h on (dd.account_id = h.account_id)&lt;BR /&gt;INNER JOIN [Schema].[dbo].[Fact_TableE] qe on (dd.account_id = qe.account_id)&lt;BR /&gt;WHERE qe.country='AU'&lt;BR /&gt;AND qe.product in ('123','909')&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;AND EXISTS(SELECT 1&lt;BR /&gt;FROM [Schema].[dbo].[Fact_TableB] fgh&lt;BR /&gt;WHERE dd.[occurance_end_dt] &amp;gt;= fgh.occurance_end_dt&lt;BR /&gt;AND dd.account_id = fgh.account_id&lt;BR /&gt;HAVING MAX(fgh.occurance_st_dt) = gr.occurance_st_dt)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;AND EXISTS(SELECT 1&lt;BR /&gt;FROM [Schema].[dbo].[Fact_TableC] ggh&lt;BR /&gt;WHERE dd.[occurance_end_dt] &amp;gt;= ggh.occurance_end_dt&lt;BR /&gt;AND dd.account_id = ggh.account_id&lt;BR /&gt;HAVING MIN(ggh.occurance_st_dt) = gh.occurance_st_dt)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;OR NOT EXISTS(SELECT 1&lt;BR /&gt;FROM [Schema].[dbo].[Fact_TableC] gggh&lt;BR /&gt;WHERE gr.account_id = gggh.account_id)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SAS Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql;&lt;BR /&gt;create table &amp;lt;Library&amp;gt;.&amp;lt;Table_name&amp;gt; as&lt;BR /&gt;select *&lt;BR /&gt;from Fact_TableA dd&lt;BR /&gt;LEFT JOIN Fact_TableB gr on (dd.account_id = gr.account_id)&lt;BR /&gt;LEFT JOIN Fact_TableC gh on (dd.account_id = gh.account_id)&lt;BR /&gt;LEFT JOIN Fact_TableD h on (dd.account_id = h.account_id)&lt;BR /&gt;INNER JOIN Fact_TableE qe on (dd.account_id = qe.account_id)&lt;BR /&gt;WHERE qe.country='AU'&lt;BR /&gt;AND qe.product in ('123','909')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AND EXISTS(SELECT 1&lt;BR /&gt;FROM Fact_TableB fgh&lt;BR /&gt;WHERE dd.occurance_end_dt &amp;gt;= fgh.occurance_end_dt&lt;BR /&gt;AND dd.account_id = fgh.account_id&lt;BR /&gt;HAVING MAX(fgh.occurance_st_dt) = gr.occurance_st_dt)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AND EXISTS(SELECT 1&lt;BR /&gt;FROM Fact_TableC ggh&lt;BR /&gt;WHERE dd.occurance_end_dt &amp;gt;= ggh.occurance_end_dt&lt;BR /&gt;AND dd.account_id = ggh.account_id&lt;BR /&gt;HAVING MIN(ggh.occurance_st_dt) = gh.occurance_st_dt)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OR NOT EXISTS(SELECT 1&lt;BR /&gt;FROM Fact_TableC gggh&lt;BR /&gt;WHERE gr.account_id = gggh.account_id)&lt;BR /&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 16:05:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/849855#M335937</guid>
      <dc:creator>prasanthor</dc:creator>
      <dc:date>2022-12-15T16:05:25Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL Server code to SAS DI 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/849870#M335938</link>
      <description>&lt;P&gt;The code you are showing as SAS code is not valid SAS SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The square brackets "[]" are not applicable for delimiting names in SAS SQL. So I wonder how you got as far as to get the machine to spend half an hour calculating with that code, I would expect it to throw an error immediately, like this:&lt;/P&gt;
&lt;PRE&gt; 69         proc sql;
 70           select * from [sashelp].[class];
                            _
                            22
                            200
 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, CONNECTION, DICTIONARY.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Is the log message from some earlier step, or did you submit something completely different?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually, the easiest solution may be to embed the existing query in a SELECT * FROM CONNECTION, something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  connect to SQLsvr (&amp;lt;connect options&amp;gt;);
  create table &amp;lt;Library&amp;gt;.&amp;lt;Table_name&amp;gt; as select * from connection to SQLsvr(
     select *
     from [Schema].[dbo].[Fact_TableA] dd &amp;lt;and all the rest of the SQL server query&amp;gt;
  );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can look up SQL passthrough for SQL server &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/p09s44hpea09stn1puyx1l5vcwwt.htm" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 15:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/849870#M335938</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-12-15T15:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL Server code to SAS DI 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/850003#M335974</link>
      <description>&lt;P&gt;A note about my first answer:&amp;nbsp;Originally, the supposed SAS SQL code in the question was actually SQL server code.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/394334"&gt;@prasanthor&lt;/a&gt;&amp;nbsp;has now replaced that with actual SAS SQL code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/394334"&gt;@prasanthor&lt;/a&gt;&amp;nbsp;: it is not a good idea to just edit the code like that, that makes the thread very confusing. Better to answer my post, admit that you made a mistake, and post the question again as it should have been.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SQL server code you show works on a number of tables that are probably indexed on the variables used in the joins, which is probably why it works. The SAS SQL code works on a number of tables in the WORK library, which are (I assume) not indexed. Where did those tables come from?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 04:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/850003#M335974</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-12-16T04:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting SQL Server code to SAS DI 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/850024#M335983</link>
      <description>&lt;P&gt;I think the key element here is:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;NOTE: The execution of this query involves performing one or more Cartesian product joins that can not be optimized.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does the code suppose to do that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Usually&lt;SPAN&gt;&amp;nbsp;cartesian joins is not what you want. But on the other hand, the SQLS and SAS code looks "identical"...?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I see two ways forward here:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Go back to the requirements&amp;nbsp;to understand what output is to produce, and then building it with an ETL flow from scratch, instead of copy/paste code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- Look into your data, compare your SAS work tables with corresponding&amp;nbsp;ones in SQLS&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2022 07:23:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-SQL-Server-code-to-SAS-DI-9-4/m-p/850024#M335983</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-12-16T07:23:05Z</dc:date>
    </item>
  </channel>
</rss>

