<?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: Proc SQL SAS :  working with multiple queries in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446741#M112138</link>
    <description>&lt;P&gt;Hello, try to describe your problem with a simple example that can be replicated&lt;/P&gt;
&lt;P&gt;by SAS forum users.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following query on sashelp.class has a form similar to your example :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    SELECT sum(HEIGHT1,WEIGHT)
    FROM sashelp.class
    WHERE HEIGHT1 IN (
              SELECT sum(HEIGHT) AS HEIGHT1
              FROM sashelp.class
              WHERE HEIGHT&amp;gt;60
    );
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot use the varaible name HEIGHT1 created in the subquery in the main query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can do as follows instead :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    SELECT sum(sum((HEIGHT&amp;gt;60)*HEIGHT),WEIGHT)
    FROM sashelp.class
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Mar 2018 12:14:30 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2018-03-19T12:14:30Z</dc:date>
    <item>
      <title>Proc SQL SAS :  working with multiple queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446707#M112127</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS Dataset names Cloudability.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am performing this query on the dataset :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL ;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;CREATE TABLE CLOUD_FINAL_PREM_SUP_NONPDX AS&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;SELECT BUSINESS_UNIT,PAYERACCOUNTID,LINKEDACCOUNTID,ACCOUNTNAME,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;( (SUM(VENDOR_COST_OF_SERVICE)/TOTAL_COST_NONPREDIX) *&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;(AWS_PREMIUM_SUPPORT - PREMIUM_SUPPORT_PREDIX) )&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;AS PREMIUM_SUPPORT FROM CLOUDABILITY&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;WHERE TOTAL_COST_NONPREDIX IN&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;( SELECT SUM(VENDOR_COST_OF_SERVICE) AS TOTAL_COST_NONPREDIX&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;FROM CLOUDABILITY WHERE BUSINESS_UNIT NOT IN ('PREDIX')&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;AND PRODUCTNAME NOT IN ('AWS PREMIUM SUPPORT') )&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;AND AWS_PREMIUM_SUPPORT IN&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;( SELECT SUM(VENDOR_COST_OF_SERVICE) AS AWS_PREMIUM_SUPPORT&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;FROM CLOUDABILITY WHERE PRODUCTNAME IN ('AWS PREMIUM SUPPORT') )&lt;BR /&gt;&lt;BR /&gt;AND PREMIUM_SUPPORT_PREDIX IN&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;( SELECT SUM(VENDOR_COST_OF_SERVICE) AS PREMIUM_SUPPORT_PREDIX&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;FROM CLOUDABILITY WHERE BUSINESS_UNIT NOT IN ('PREDIX') )&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;AND BUSINESS_UNIT NOT IN ('PREDIX')&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;AND PRODUCTNAME NOT IN ('AWS PREMIUM SUPPORT')&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;GROUP BY BUSINESS_UNIT,PAYERACCOUNTID,LINKEDACCOUNTID,ACCOUNTNAME&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;QUIT ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I am getting an error :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: The following columns were not found in the contributing tables:AWS_PREMIUM_SUPPORT, PREMIUM_SUPPORT_PREDIX,&amp;nbsp;TOTAL_COST_NONPREDIX&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me with this&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 10:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446707#M112127</guid>
      <dc:creator>sayanapex06</dc:creator>
      <dc:date>2018-03-19T10:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL SAS :  working with multiple queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446716#M112132</link>
      <description>&lt;P&gt;Look like you are missing a FROM clause...&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 11:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446716#M112132</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-19T11:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL SAS :  working with multiple queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446741#M112138</link>
      <description>&lt;P&gt;Hello, try to describe your problem with a simple example that can be replicated&lt;/P&gt;
&lt;P&gt;by SAS forum users.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following query on sashelp.class has a form similar to your example :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    SELECT sum(HEIGHT1,WEIGHT)
    FROM sashelp.class
    WHERE HEIGHT1 IN (
              SELECT sum(HEIGHT) AS HEIGHT1
              FROM sashelp.class
              WHERE HEIGHT&amp;gt;60
    );
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You cannot use the varaible name HEIGHT1 created in the subquery in the main query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can do as follows instead :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    SELECT sum(sum((HEIGHT&amp;gt;60)*HEIGHT),WEIGHT)
    FROM sashelp.class
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Mar 2018 12:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446741#M112138</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-03-19T12:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL SAS :  working with multiple queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446779#M112155</link>
      <description>&lt;P&gt;After reformatting your code to make it readable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create table CLOUD_FINAL_PREM_SUP_NONPDX as
select
  BUSINESS_UNIT,
  PAYERACCOUNTID,
  LINKEDACCOUNTID,
  ACCOUNTNAME,
  (
    sum(VENDOR_COST_OF_SERVICE) / TOTAL_COST_NONPREDIX *
    (AWS_PREMIUM_SUPPORT - PREMIUM_SUPPORT_PREDIX)
  ) as PREMIUM_SUPPORT
from CLOUDABILITY
where
  TOTAL_COST_NONPREDIX in (
    select sum(VENDOR_COST_OF_SERVICE) as TOTAL_COST_NONPREDIX
    from CLOUDABILITY
    where BUSINESS_UNIT ne 'PREDIX' and PRODUCTNAME ne 'AWS PREMIUM SUPPORT'
  )
  and
  AWS_PREMIUM_SUPPORT in (
    select sum(VENDOR_COST_OF_SERVICE) as AWS_PREMIUM_SUPPORT
    from CLOUDABILITY
    where PRODUCTNAME = 'AWS PREMIUM SUPPORT'
  )
  and
  PREMIUM_SUPPORT_PREDIX in (
    select sum(VENDOR_COST_OF_SERVICE) as PREMIUM_SUPPORT_PREDIX
    from CLOUDABILITY
    where BUSINESS_UNIT ne 'PREDIX'
  )
  and
  BUSINESS_UNIT ne 'PREDIX'
  and
  PRODUCTNAME ne 'AWS PREMIUM SUPPORT'
group by BUSINESS_UNIT,PAYERACCOUNTID,LINKEDACCOUNTID,ACCOUNTNAME
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I see no obvious problem with the SQL structure, all selects have their from.&lt;/P&gt;
&lt;P&gt;Do a proc contents on dataset cloudability to see if all columns/variables are there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: we have left the stone-age of computing with the introduction of the ASCII table and basically all compilers/interpreters can read lowercase perfectly well. No need to shout at them anymore.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 14:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446779#M112155</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T14:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL SAS :  working with multiple queries</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446781#M112157</link>
      <description>&lt;P&gt;PS It would be of great help if you used the macro from&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; to create a datastep version of your dataset and post that here. Follow the advice in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce" target="_blank"&gt;https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce&lt;/A&gt; for posting code.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 14:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-SAS-working-with-multiple-queries/m-p/446781#M112157</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-19T14:14:10Z</dc:date>
    </item>
  </channel>
</rss>

