<?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: Create global temporary table from result of sql code with multi joins in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593797#M170488</link>
    <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the link. I could not create temporay table as&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***" CONNECTION=GLOBAL);&lt;/P&gt;&lt;P&gt;EXECUTE(&lt;/P&gt;&lt;P&gt;CREATE TABLE ##T1 AS&lt;/P&gt;&lt;P&gt;SELECT * FROM ABC);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But was able to create it as&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***" CONNECTION=GLOBAL);&lt;/P&gt;&lt;P&gt;EXECUTE(&lt;/P&gt;&lt;P&gt;create table ##T1&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;COL1 VARCHAR(30),&lt;/P&gt;&lt;P&gt;COL2 VARCHAR(30)&lt;/P&gt;&lt;P&gt;))BY A;&lt;/P&gt;&lt;P&gt;and populate the temp table as below&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***" CONNECTION=GLOBAL);&lt;/P&gt;&lt;P&gt;EXECUTE(&lt;/P&gt;&lt;P&gt;INSERT ##T1&lt;/P&gt;&lt;P&gt;SELECT * FROM ABC);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I create a SAS data set from the ##T1 temp data source?&lt;/P&gt;&lt;P&gt;I also want to be able to reference this temp table to create another temp table that uses above table in join&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 16:18:09 GMT</pubDate>
    <dc:creator>SoloDolo</dc:creator>
    <dc:date>2019-10-03T16:18:09Z</dc:date>
    <item>
      <title>Create global temporary table from result of sql code with multi joins in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593447#M170304</link>
      <description>&lt;P&gt;Hi SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a scenario where I have several sql server data source tables. I have read only access to these sources. I cannot create permanent tables in Sql Server environment. I can however create temporary tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought of creating global temporary table out of scenario 1 result set and reference that in scenario 2(again create second global temp table in scenario 2 ) and 3rd global temp table out of third sql code. I have included generic sql below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally create a SAS data set out of each of these global temp tables.(We want to ensure all joins, data transformation needs to happen in sql server and not perform it in SAS)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Scenario1-&lt;/P&gt;&lt;P&gt;select * from table1 join table2&lt;/P&gt;&lt;P&gt;on table1.id=table2.id&lt;/P&gt;&lt;P&gt;where table1.product='Apple'&lt;/P&gt;&lt;P&gt;Scenario-2&lt;/P&gt;&lt;P&gt;Above result is then used in another query as&lt;/P&gt;&lt;P&gt;select * from table3 m&lt;/P&gt;&lt;P&gt;left join above _result_table t&lt;/P&gt;&lt;P&gt;on m.id=t.id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the above result is again referenced further.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried researching online to find similar issue implementation and I could not find it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried below code, but this creates a SAS data set , I want to instead create a global temporary table so that another query such as below can reference it. How do I accomplish that?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;/P&gt;&lt;P&gt;connect to odbc(dsn=abc user=123 pw=****** connection=shared);&lt;/P&gt;&lt;P&gt;create table xyz as select * from&lt;/P&gt;&lt;P&gt;connectoin to ODBC&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;select * from table1 join table2&lt;/P&gt;&lt;P&gt;on table1.id=table2.id&lt;/P&gt;&lt;P&gt;where table1.product='Apple'&lt;/P&gt;&lt;P&gt;);DISCONNECT FROM ODBC;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solo&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 16:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593447#M170304</guid>
      <dc:creator>SoloDolo</dc:creator>
      <dc:date>2019-10-02T16:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create global temporary table from result of sql code with multi joins in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593522#M170333</link>
      <description>&lt;P&gt;&lt;BR /&gt;You need an EXECUTE() block like shown&amp;nbsp;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Creating-temp-table-in-sql-server-pass-through/td-p/89454" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2019 19:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593522#M170333</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-10-02T19:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create global temporary table from result of sql code with multi joins in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593797#M170488</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the link. I could not create temporay table as&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***" CONNECTION=GLOBAL);&lt;/P&gt;&lt;P&gt;EXECUTE(&lt;/P&gt;&lt;P&gt;CREATE TABLE ##T1 AS&lt;/P&gt;&lt;P&gt;SELECT * FROM ABC);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But was able to create it as&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***" CONNECTION=GLOBAL);&lt;/P&gt;&lt;P&gt;EXECUTE(&lt;/P&gt;&lt;P&gt;create table ##T1&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;COL1 VARCHAR(30),&lt;/P&gt;&lt;P&gt;COL2 VARCHAR(30)&lt;/P&gt;&lt;P&gt;))BY A;&lt;/P&gt;&lt;P&gt;and populate the temp table as below&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***" CONNECTION=GLOBAL);&lt;/P&gt;&lt;P&gt;EXECUTE(&lt;/P&gt;&lt;P&gt;INSERT ##T1&lt;/P&gt;&lt;P&gt;SELECT * FROM ABC);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I create a SAS data set from the ##T1 temp data source?&lt;/P&gt;&lt;P&gt;I also want to be able to reference this temp table to create another temp table that uses above table in join&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 16:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593797#M170488</guid>
      <dc:creator>SoloDolo</dc:creator>
      <dc:date>2019-10-03T16:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create global temporary table from result of sql code with multi joins in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593801#M170489</link>
      <description>&lt;P&gt;Just select from it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CONNECT TO ODBC AS A(DSN=SRC USER=ABC PW="***"  CONNECTION=GLOBAL);
EXECUTE (
  create table ##T1
  (COL1 VARCHAR(30)
  ,COL2 VARCHAR(30)
  )
) BY A;
EXECUTE (
  INSERT ##T1
  SELECT * FROM ABC
) BY A;
create table MYSASTABLE as 
select * from connection to A
(
  select * from ##T1
)
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 16:32:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593801#M170489</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-03T16:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create global temporary table from result of sql code with multi joins in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593901#M170538</link>
      <description>&lt;P&gt;Thank You, this worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 20:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-global-temporary-table-from-result-of-sql-code-with-multi/m-p/593901#M170538</guid>
      <dc:creator>SoloDolo</dc:creator>
      <dc:date>2019-10-03T20:24:18Z</dc:date>
    </item>
  </channel>
</rss>

