<?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 defining table as object in second query in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179946#M13730</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm new to SAS so apologize for the newbie question - I can't figure this task out.&amp;nbsp;&amp;nbsp;&amp;nbsp; I have a&amp;nbsp; two part query - first part creates a table of records and second part uses that table.&amp;nbsp; Basically I want to tell the second query to go look up the data in the first table and then match on it in a second table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simplistic example below - I create table 'car_list' with a single column of data 'model_id'.&amp;nbsp; I then match only those model ID's in a second table to pull sales and locations.&amp;nbsp; This second query creates and outputs 'sales_summary' table.&amp;nbsp;&amp;nbsp; The first process correctly creates 'car_list'', but the second query returns error message Object 'car_list' does not exist.&amp;nbsp; How do I retrieve the model_id in 'car_list' table to use in 2nd process?&amp;nbsp; Does it go in FROM section or I do have to do some kind of In List function?&amp;nbsp; *This is several million rows so copy/pasting in the output from Query 1 is not an option&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect to...;&lt;/P&gt;&lt;P&gt;create table car_list as ...(&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; model_id&lt;/P&gt;&lt;P&gt;from&amp;nbsp; datasource1.model_list&lt;/P&gt;&lt;P&gt;where model_id in (a,b,c,d,e)&lt;/P&gt;&lt;P&gt;);quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect to...;&lt;/P&gt;&lt;P&gt;create table sales_summary as ...(&lt;BR /&gt;&amp;nbsp; select&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(a.sales) as Sales,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(a.locations) as Locations&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;from&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasource2.sales a,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; car_list b&lt;/P&gt;&lt;P&gt;where&amp;nbsp; a.model_id = b.model_id&lt;/P&gt;&lt;P&gt;group by 1,2&lt;/P&gt;&lt;P&gt;);quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 21 Dec 2013 02:42:34 GMT</pubDate>
    <dc:creator>atljogger</dc:creator>
    <dc:date>2013-12-21T02:42:34Z</dc:date>
    <item>
      <title>Proc SQL defining table as object in second query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179946#M13730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm new to SAS so apologize for the newbie question - I can't figure this task out.&amp;nbsp;&amp;nbsp;&amp;nbsp; I have a&amp;nbsp; two part query - first part creates a table of records and second part uses that table.&amp;nbsp; Basically I want to tell the second query to go look up the data in the first table and then match on it in a second table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Simplistic example below - I create table 'car_list' with a single column of data 'model_id'.&amp;nbsp; I then match only those model ID's in a second table to pull sales and locations.&amp;nbsp; This second query creates and outputs 'sales_summary' table.&amp;nbsp;&amp;nbsp; The first process correctly creates 'car_list'', but the second query returns error message Object 'car_list' does not exist.&amp;nbsp; How do I retrieve the model_id in 'car_list' table to use in 2nd process?&amp;nbsp; Does it go in FROM section or I do have to do some kind of In List function?&amp;nbsp; *This is several million rows so copy/pasting in the output from Query 1 is not an option&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect to...;&lt;/P&gt;&lt;P&gt;create table car_list as ...(&lt;/P&gt;&lt;P&gt;&amp;nbsp; select&amp;nbsp; model_id&lt;/P&gt;&lt;P&gt;from&amp;nbsp; datasource1.model_list&lt;/P&gt;&lt;P&gt;where model_id in (a,b,c,d,e)&lt;/P&gt;&lt;P&gt;);quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect to...;&lt;/P&gt;&lt;P&gt;create table sales_summary as ...(&lt;BR /&gt;&amp;nbsp; select&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(a.sales) as Sales,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(a.locations) as Locations&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;from&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasource2.sales a,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; car_list b&lt;/P&gt;&lt;P&gt;where&amp;nbsp; a.model_id = b.model_id&lt;/P&gt;&lt;P&gt;group by 1,2&lt;/P&gt;&lt;P&gt;);quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Dec 2013 02:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179946#M13730</guid>
      <dc:creator>atljogger</dc:creator>
      <dc:date>2013-12-21T02:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL defining table as object in second query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179947#M13731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure I understand what you are doing. The problem seem to be that you are asking a server to join a table that was created on your local machine (car_list) with a table that resides on the server (sales). The server doesn't know where your SAS table is. If both queries are pass-through queries run on the same database then they could be combined into a single query that would be run on the server without creating the local table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Dec 2013 04:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179947#M13731</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-12-21T04:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL defining table as object in second query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179948#M13732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So this is poor example as to fix this just copy the WHERE clause from the first query to the second.&lt;/P&gt;&lt;P&gt;But in the general case you can embed the first query as a sub query in the second.&amp;nbsp; This syntax will work in SAS, but you need to check whether it will work in your database system.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;connect to ... as db (...);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;create table sales_summary as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select * from connection to db&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;( select sum(a.sales) as Sales&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , count(a.locations) as Locations&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from datasource2.sales a&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , (&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select model_id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from datasource1.model_list&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where model_id in (a,b,c,d,e)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ) b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; where a.model_id = b.model_id&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; group by 1 ,2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Dec 2013 14:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179948#M13732</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-12-21T14:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL defining table as object in second query</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179949#M13733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you both.&amp;nbsp; Embedding the sub-query worked perfect.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Dec 2013 17:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-SQL-defining-table-as-object-in-second-query/m-p/179949#M13733</guid>
      <dc:creator>atljogger</dc:creator>
      <dc:date>2013-12-21T17:12:01Z</dc:date>
    </item>
  </channel>
</rss>

