<?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: SQL script converted to Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749691#M235650</link>
    <description>I do not know if they do.</description>
    <pubDate>Tue, 22 Jun 2021 19:52:52 GMT</pubDate>
    <dc:creator>aamoen</dc:creator>
    <dc:date>2021-06-22T19:52:52Z</dc:date>
    <item>
      <title>SQL script converted to Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749626#M235609</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Recently I took a SQL query that I was running in Teradata SQL Assistant and wrote it in SAS using Proc SQL.&amp;nbsp; My intend was to get the same results in SAS as I was getting the script in Teradata SQL Assistant.&amp;nbsp; The Proc SQL code works, however I'm getting slightly different results and I'm not sure why.&amp;nbsp; Does anyone know what I might be missing?&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Teradata SQL Assistant code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Select&lt;BR /&gt;PERIOD_DT as "Date"&lt;BR /&gt;,APPL&lt;BR /&gt;,CUST_TYPE_IND&lt;BR /&gt;,SUBPROD_CODE&lt;BR /&gt;,left(NAICS_Code,2) as "NAIC 2 Digit"&lt;BR /&gt;,CUOV_BUSN_TYPE&lt;BR /&gt;,sum(CUR_BAL) as "Balance"&lt;BR /&gt;From eiw_d_bicc_hgnids_v1.depsme_jv IDS&lt;BR /&gt;left join CIS.CUSTOMER_TB Cust&lt;BR /&gt;on IDS.CIS_CUST_NO = Cust.Cust_NBR&lt;BR /&gt;and cust.Close_date is null&lt;/P&gt;&lt;P&gt;Left Join CIS.Cust_OV_TB CUOV&lt;BR /&gt;On CUST.Cust_CO_NBR = CUOV.Cust_CO_NBR&lt;BR /&gt;and CUST.CUST_ID = CUOV.CUST_ID&lt;BR /&gt;AND CUST.CUST_TIE_BRKR = CUOV.CUST_TIE_BRKR&lt;/P&gt;&lt;P&gt;left join PCD.NAICS_TB NAIC&lt;BR /&gt;on Cust.NAIC_CD = NAIC.NAICS_Code&lt;/P&gt;&lt;P&gt;where IDS.PERIOD_DT = '2021-05-31'&lt;BR /&gt;and IDS.CUR_BAL &amp;gt;0&lt;BR /&gt;and CUST_TYPE_IND &amp;lt;&amp;gt; 0&lt;BR /&gt;and IDS.CUR_BAL &amp;lt;1000000&lt;BR /&gt;and NAIC.NAICS_Code not in (&lt;BR /&gt;'521110', '522110', '522120', '522130', '522190', '522210')&lt;BR /&gt;group by&lt;BR /&gt;1,2,3,4,5,6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SAS Proc SQL code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;call Execute('%include "/users/apps/rbr_rpa/&amp;amp;sysuserid/pw/teradata_credentials.sas " / source2;');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;libname teralib1 teradata server='XXXXX' user=&amp;amp;tduser password=&amp;amp;pw database='eiw_d_bicc_hgnids_v1';&lt;BR /&gt;libname teralib2 teradata server='XXXXX' user=&amp;amp;tduser password=&amp;amp;pw database='CIS';&lt;BR /&gt;libname teralib3 teradata server='XXXXX' user=&amp;amp;tduser password=&amp;amp;pw database='PCD' mode=teradata;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table small_business as&lt;BR /&gt;select&lt;BR /&gt;depsme_jv.PERIOD_DT as Date,&lt;BR /&gt;depsme_jv.APPL,&lt;BR /&gt;CUSTOMER_TB.CUST_TYPE_IND,&lt;BR /&gt;depsme_jv.SUBPROD_CODE,&lt;BR /&gt;substr(naics_tb.NAICS_Code,1,2) as NAIC_2_Digit,&lt;BR /&gt;cust_ov_tb.CUOV_BUSN_TYPE,&lt;BR /&gt;sum(depsme_jv.CUR_BAL) as Balance&lt;/P&gt;&lt;P&gt;from teralib1.depsme_jv&lt;BR /&gt;left join teralib2.customer_tb&lt;BR /&gt;on depsme_jv.cis_cust_no = customer_tb.Cust_NBR and customer_tb.close_date is null&lt;/P&gt;&lt;P&gt;left join teralib2.cust_ov_tb&lt;BR /&gt;on customer_tb.Cust_CO_NBR = cust_ov_tb.Cust_CO_NBR&lt;BR /&gt;and customer_tb.CUST_ID = cust_ov_tb.CUST_ID&lt;BR /&gt;and customer_tb.CUST_TIE_BRKR = cust_ov_tb.CUST_TIE_BRKR&lt;/P&gt;&lt;P&gt;left join teralib3.naics_tb&lt;BR /&gt;on customer_tb.naic_cd = naics_tb.naics_code&lt;/P&gt;&lt;P&gt;where depsme_jv.PERIOD_DT='31May2021'd&lt;BR /&gt;and depsme_jv.cur_bal &amp;gt; 0&lt;BR /&gt;and CUSTOMER_TB.cust_type_ind ~="0"&lt;BR /&gt;and CUSTOMER_TB.cust_type_ind is not null&lt;BR /&gt;and depsme_jv.cur_bal &amp;lt; 1000000&lt;BR /&gt;and naics_tb.naics_code not in('521110', '522110', '522120', '522130', '522190', '522210')&lt;BR /&gt;and naics_tb.naics_code is not null&lt;BR /&gt;group by 1,2,3,4,5,6;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;libname teralib1 clear;&lt;BR /&gt;libname teralib2 clear;&lt;BR /&gt;libname teralib3 clear;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 16:36:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749626#M235609</guid>
      <dc:creator>aamoen</dc:creator>
      <dc:date>2021-06-22T16:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: SQL script converted to Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749651#M235627</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;and CUSTOMER_TB.cust_type_ind ~="0"
and CUSTOMER_TB.cust_type_ind is not null&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;and CUSTOMER_TB.cust_type_ind ne "0"
and not missing(CUSTOMER_TB.cust_type_ind) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try replacing those two lines with the ones below that's my first guess after a quick scan of the code. And how far off are you?&lt;/P&gt;
&lt;P&gt;If you generate the query without the summarization does it return the same number of rows?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/331774"&gt;@aamoen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;Recently I took a SQL query that I was running in Teradata SQL Assistant and wrote it in SAS using Proc SQL.&amp;nbsp; My intend was to get the same results in SAS as I was getting the script in Teradata SQL Assistant.&amp;nbsp; The Proc SQL code works, however I'm getting slightly different results and I'm not sure why.&amp;nbsp; Does anyone know what I might be missing?&amp;nbsp; Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Teradata SQL Assistant code:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Select&lt;BR /&gt;PERIOD_DT as "Date"&lt;BR /&gt;,APPL&lt;BR /&gt;,CUST_TYPE_IND&lt;BR /&gt;,SUBPROD_CODE&lt;BR /&gt;,left(NAICS_Code,2) as "NAIC 2 Digit"&lt;BR /&gt;,CUOV_BUSN_TYPE&lt;BR /&gt;,sum(CUR_BAL) as "Balance"&lt;BR /&gt;From eiw_d_bicc_hgnids_v1.depsme_jv IDS&lt;BR /&gt;left join CIS.CUSTOMER_TB Cust&lt;BR /&gt;on IDS.CIS_CUST_NO = Cust.Cust_NBR&lt;BR /&gt;and cust.Close_date is null&lt;/P&gt;
&lt;P&gt;Left Join CIS.Cust_OV_TB CUOV&lt;BR /&gt;On CUST.Cust_CO_NBR = CUOV.Cust_CO_NBR&lt;BR /&gt;and CUST.CUST_ID = CUOV.CUST_ID&lt;BR /&gt;AND CUST.CUST_TIE_BRKR = CUOV.CUST_TIE_BRKR&lt;/P&gt;
&lt;P&gt;left join PCD.NAICS_TB NAIC&lt;BR /&gt;on Cust.NAIC_CD = NAIC.NAICS_Code&lt;/P&gt;
&lt;P&gt;where IDS.PERIOD_DT = '2021-05-31'&lt;BR /&gt;and IDS.CUR_BAL &amp;gt;0&lt;BR /&gt;and CUST_TYPE_IND &amp;lt;&amp;gt; 0&lt;BR /&gt;and IDS.CUR_BAL &amp;lt;1000000&lt;BR /&gt;and NAIC.NAICS_Code not in (&lt;BR /&gt;'521110', '522110', '522120', '522130', '522190', '522210')&lt;BR /&gt;group by&lt;BR /&gt;1,2,3,4,5,6&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SAS Proc SQL code:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;call Execute('%include "/users/apps/rbr_rpa/&amp;amp;sysuserid/pw/teradata_credentials.sas " / source2;');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;libname teralib1 teradata server='XXXXX' user=&amp;amp;tduser password=&amp;amp;pw database='eiw_d_bicc_hgnids_v1';&lt;BR /&gt;libname teralib2 teradata server='XXXXX' user=&amp;amp;tduser password=&amp;amp;pw database='CIS';&lt;BR /&gt;libname teralib3 teradata server='XXXXX' user=&amp;amp;tduser password=&amp;amp;pw database='PCD' mode=teradata;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table small_business as&lt;BR /&gt;select&lt;BR /&gt;depsme_jv.PERIOD_DT as Date,&lt;BR /&gt;depsme_jv.APPL,&lt;BR /&gt;CUSTOMER_TB.CUST_TYPE_IND,&lt;BR /&gt;depsme_jv.SUBPROD_CODE,&lt;BR /&gt;substr(naics_tb.NAICS_Code,1,2) as NAIC_2_Digit,&lt;BR /&gt;cust_ov_tb.CUOV_BUSN_TYPE,&lt;BR /&gt;sum(depsme_jv.CUR_BAL) as Balance&lt;/P&gt;
&lt;P&gt;from teralib1.depsme_jv&lt;BR /&gt;left join teralib2.customer_tb&lt;BR /&gt;on depsme_jv.cis_cust_no = customer_tb.Cust_NBR and customer_tb.close_date is null&lt;/P&gt;
&lt;P&gt;left join teralib2.cust_ov_tb&lt;BR /&gt;on customer_tb.Cust_CO_NBR = cust_ov_tb.Cust_CO_NBR&lt;BR /&gt;and customer_tb.CUST_ID = cust_ov_tb.CUST_ID&lt;BR /&gt;and customer_tb.CUST_TIE_BRKR = cust_ov_tb.CUST_TIE_BRKR&lt;/P&gt;
&lt;P&gt;left join teralib3.naics_tb&lt;BR /&gt;on customer_tb.naic_cd = naics_tb.naics_code&lt;/P&gt;
&lt;P&gt;where depsme_jv.PERIOD_DT='31May2021'd&lt;BR /&gt;and depsme_jv.cur_bal &amp;gt; 0&lt;BR /&gt;and CUSTOMER_TB.cust_type_ind ~="0"&lt;BR /&gt;and CUSTOMER_TB.cust_type_ind is not null&lt;BR /&gt;and depsme_jv.cur_bal &amp;lt; 1000000&lt;BR /&gt;and naics_tb.naics_code not in('521110', '522110', '522120', '522130', '522190', '522210')&lt;BR /&gt;and naics_tb.naics_code is not null&lt;BR /&gt;group by 1,2,3,4,5,6;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;libname teralib1 clear;&lt;BR /&gt;libname teralib2 clear;&lt;BR /&gt;libname teralib3 clear;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 17:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749651#M235627</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-22T17:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: SQL script converted to Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749657#M235630</link>
      <description>&lt;P&gt;By default Teradata ignores case when comparing strings.&lt;/P&gt;
&lt;P&gt;Do you know if any of the character strings have mixed case?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 17:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749657#M235630</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-06-22T17:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: SQL script converted to Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749687#M235649</link>
      <description>&lt;P&gt;Interestingly enough, the total balance of the output is the same.&amp;nbsp; But Proc SQL is bringing back fewer rows.&amp;nbsp; 6,224 rows from the Teradata SQL Assistant output versus 6,203 rows from Proc SQL.&amp;nbsp; So it seems that the grouping is working differently between the two.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 19:29:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749687#M235649</guid>
      <dc:creator>aamoen</dc:creator>
      <dc:date>2021-06-22T19:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: SQL script converted to Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749691#M235650</link>
      <description>I do not know if they do.</description>
      <pubDate>Tue, 22 Jun 2021 19:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749691#M235650</guid>
      <dc:creator>aamoen</dc:creator>
      <dc:date>2021-06-22T19:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: SQL script converted to Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749938#M235788</link>
      <description>&lt;P&gt;I suggest use Proc compare to compare the two outputs.&lt;BR /&gt;That will help understand what is going on.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 18:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-script-converted-to-Proc-SQL/m-p/749938#M235788</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-06-23T18:29:40Z</dc:date>
    </item>
  </channel>
</rss>

