<?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: Splitting the SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442885#M110767</link>
    <description>&lt;P&gt;Basic guide, just leave out the GROUP BY statement, and the aggregate functions in the first step, and introduce them in the next.&lt;/P&gt;
&lt;P&gt;FTR: some of the SUM() in your SQL is not aggregate functions, these are SAS functions that summarize columns vales per row (on those should be kept in the first step).&lt;/P&gt;</description>
    <pubDate>Tue, 06 Mar 2018 14:07:20 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2018-03-06T14:07:20Z</dc:date>
    <item>
      <title>Splitting the SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442878#M110764</link>
      <description>&lt;P&gt;Is there any way to split the below PROC SQL? Client has asked me to do it two steps as follows.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;first create new amounts (comm_amt, prem_amt, basis_amt)&lt;/LI&gt;
&lt;LI&gt;than summarize the newly created amounts columns for the group by variables&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;In the above two steps, I'm not certain on which condition I can do the group by. Appreciate if someone of you guide me here/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE OUTPUT_dijob AS
SELECT DOMAIN,
     INSURANCE_PRODUCT_CD,
     LOB_RK,
     PRODUCER_RK,
     X_PERIL_RK,
     PREMIUM_BEG_DT,
     PREMIUM_END_DT,
     SOURCE_SYSTEM_CD,
     CREATOR_SOURCE_SYSTEM_CD,
     POLICY_NO,
     POLICY_RK,
     INVOICE_NO,
     CURRENCY_CD,
     sum('613113412300'n) as COMM_AMT,
     sum ('7101100000'n ,
         '7101100010'n ,
         '7101101000'n ,
         '710110134010'n ,
          '7101110000'n ,
              '7101111000'n ,
         '7101150020'n ,
         '7101150030'n ,
         '7101300000'n ) as PREM_AMT,
     sum( '6131112300'n,
          '710110000450'n ,
           '7101100010'n ,
               '7101101000'n ,
          '7101101010'n ,
          '7101110000'n ,
               '710111541000'n ,
               '7101150020'n ,
          '7101150030'n ,
               '7101300000'n) as BASIS_AMT
FROM dextc._COMM_POL_PREM_201702
where upcase(domain)='NL' and '21feb2017'd between PREMIUM_BEG_DT and PREMIUM_END_DT
GROUP BY
DOMAIN,
INSURANCE_PRODUCT_CD,
LOB_RK,
PRODUCER_RK,
X_PERIL_RK,
PREMIUM_BEG_DT,
PREMIUM_END_DT,
SOURCE_SYSTEM_CD,
CREATOR_SOURCE_SYSTEM_CD,
POLICY_NO,
POLICY_RK,
INVOICE_NO,
CURRENCY_CD
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 13:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442878#M110764</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-03-06T13:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442885#M110767</link>
      <description>&lt;P&gt;Basic guide, just leave out the GROUP BY statement, and the aggregate functions in the first step, and introduce them in the next.&lt;/P&gt;
&lt;P&gt;FTR: some of the SUM() in your SQL is not aggregate functions, these are SAS functions that summarize columns vales per row (on those should be kept in the first step).&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 14:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442885#M110767</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-06T14:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442891#M110768</link>
      <description>Appreciate if you could give me the skeleton of the code. I'm not sure what&lt;BR /&gt;aggregate function should I use in the second step as I need to use 'group&lt;BR /&gt;by' here.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Mar 2018 14:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442891#M110768</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-03-06T14:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442908#M110778</link>
      <description>&lt;P&gt;The skeleton is your original code.&lt;/P&gt;
&lt;P&gt;You should be able to at least use trial and error method to get what you want.&lt;/P&gt;
&lt;P&gt;If not, get SQL training - this is basic stuff.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 14:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442908#M110778</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-06T14:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting the SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442929#M110787</link>
      <description>&lt;P&gt;Remember that there is a difference between the SQL aggregate function SUM(), which takes one and only one argument, and the SAS function SUM(,) which takes two or more arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you need to use both.&amp;nbsp; To make the pattern consistent I added an extra argument into the first derived variable.&amp;nbsp; You could just remove the SAS sum(,) function since you already only have only one argument.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CREATE TABLE OUTPUT_dijob AS
SELECT
     DOMAIN
    ,INSURANCE_PRODUCT_CD
    ,LOB_RK
    ,PRODUCER_RK
    ,X_PERIL_RK
    ,PREMIUM_BEG_DT
    ,PREMIUM_END_DT
    ,SOURCE_SYSTEM_CD
    ,CREATOR_SOURCE_SYSTEM_CD
    ,POLICY_NO
    ,POLICY_RK
    ,INVOICE_NO
    ,CURRENCY_CD
    ,sum(sum(.,'613113412300'n)) as COMM_AMT
    ,sum(sum('7101100000'n ,'7101100010'n ,'7101101000'n ,'710110134010'n
        ,'7101110000'n ,'7101111000'n ,'7101150020'n ,'7101150030'n ,'7101300000'n 
        )) as PREM_AMT
    ,sum(sum('6131112300'n ,'710110000450'n ,'7101100010'n ,'7101101000'n 
        ,'7101101010'n ,'7101110000'n ,'710111541000'n ,'7101150020'n 
        ,'7101150030'n ,'7101300000'n
        )) as BASIS_AMT
FROM dextc._COMM_POL_PREM_201702
where upcase(domain)='NL'
  and '21feb2017'd between PREMIUM_BEG_DT and PREMIUM_END_DT
GROUP BY
     DOMAIN
    ,INSURANCE_PRODUCT_CD
    ,LOB_RK
    ,PRODUCER_RK
    ,X_PERIL_RK
    ,PREMIUM_BEG_DT
    ,PREMIUM_END_DT
    ,SOURCE_SYSTEM_CD
    ,CREATOR_SOURCE_SYSTEM_CD
    ,POLICY_NO
    ,POLICY_RK
    ,INVOICE_NO
    ,CURRENCY_CD
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 15:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-the-SQL/m-p/442929#M110787</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-06T15:31:19Z</dc:date>
    </item>
  </channel>
</rss>

