<?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 how to create a table using a with tablename as statement with a snow flake pass trough connection in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979015#M46267</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using a SQL pass through connection to create the table TEMPTBL (see the script below).&amp;nbsp; Unfortunately, this table will be created in work, not into the selected schema.&amp;nbsp; So, If I want to make a left join with this table in another SQL pass through query, the table is not into the selected schema.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to convert the script below to something using with TEMPTBL AS&amp;nbsp; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;


proc sql;
connect to snow(&amp;amp;cn_SNOW.);
     %check_table(work,TEMPTBL);
     create table TEMPTBL as
      select * from connection to snow 
     (
      select 	contractVer.DIM_PL_CNTRCT_VER_KEY,
               LKPPGM.*,
		     'O' as Affinity_Ind		

from CONTRACTPL_DM.DIM_PL_CNTRCT_VER &amp;amp;timestamp. as contractVer 
join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. as LKPPGM 
ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
order by contractVer.DIM_PL_CNTRCT_VER_KEY
     
     ) ;
             
        disconnect from snow;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How to convert that script to something like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/

%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;cn_SNOW.);     
     
      select * from connection to snow 
     (
          WITH TEMPTBL as
          (
               select 	contractVer.DIM_PL_CNTRCT_VER_KEY,
                         LKPPGM.*,
                         'O' as Affinity_Ind		

               from CONTRACTPL_DM.DIM_PL_CNTRCT_VER &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. as LKPPGM 
               ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
               where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
               order by contractVer.DIM_PL_CNTRCT_VER_KEY
            )
     
     ) ;
             
        disconnect from snow;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR: CLI prepare error: SQL compilation error: syntax error line 1 at position 468 unexpected '&amp;lt;EOF&amp;gt;'.&lt;BR /&gt;SQL statement: WITH TEMPTBL as ( select contractVer.DIM_PL_CNTRCT_VER_KEY, LKPPGM.*, 'O' as Affinity_Ind from &lt;BR /&gt;CONTRACTPL_DM.DIM_PL_CNTRCT_VER at(timestamp=&amp;gt; '2025-11-11 10:33:20'::timestamp_ltz) as contractVer join &lt;BR /&gt;CONTRACTPL_DM.LKP_PROGRAM at(timestamp=&amp;gt; '2025-11-11 10:33:20'::timestamp_ltz) as LKPPGM ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = &lt;BR /&gt;contractVer.DIM_PL_CNTRCT_VER_KEY where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM' order by &lt;BR /&gt;contractVer.DIM_PL_CNTRCT_VER_KEY ).&lt;/P&gt;</description>
    <pubDate>Tue, 18 Nov 2025 15:32:05 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2025-11-18T15:32:05Z</dc:date>
    <item>
      <title>how to create a table using a with tablename as statement with a snow flake pass trough connection</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979015#M46267</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using a SQL pass through connection to create the table TEMPTBL (see the script below).&amp;nbsp; Unfortunately, this table will be created in work, not into the selected schema.&amp;nbsp; So, If I want to make a left join with this table in another SQL pass through query, the table is not into the selected schema.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to convert the script below to something using with TEMPTBL AS&amp;nbsp; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;


proc sql;
connect to snow(&amp;amp;cn_SNOW.);
     %check_table(work,TEMPTBL);
     create table TEMPTBL as
      select * from connection to snow 
     (
      select 	contractVer.DIM_PL_CNTRCT_VER_KEY,
               LKPPGM.*,
		     'O' as Affinity_Ind		

from CONTRACTPL_DM.DIM_PL_CNTRCT_VER &amp;amp;timestamp. as contractVer 
join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. as LKPPGM 
ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
order by contractVer.DIM_PL_CNTRCT_VER_KEY
     
     ) ;
             
        disconnect from snow;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How to convert that script to something like below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/

%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;cn_SNOW.);     
     
      select * from connection to snow 
     (
          WITH TEMPTBL as
          (
               select 	contractVer.DIM_PL_CNTRCT_VER_KEY,
                         LKPPGM.*,
                         'O' as Affinity_Ind		

               from CONTRACTPL_DM.DIM_PL_CNTRCT_VER &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. as LKPPGM 
               ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
               where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
               order by contractVer.DIM_PL_CNTRCT_VER_KEY
            )
     
     ) ;
             
        disconnect from snow;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;ERROR: CLI prepare error: SQL compilation error: syntax error line 1 at position 468 unexpected '&amp;lt;EOF&amp;gt;'.&lt;BR /&gt;SQL statement: WITH TEMPTBL as ( select contractVer.DIM_PL_CNTRCT_VER_KEY, LKPPGM.*, 'O' as Affinity_Ind from &lt;BR /&gt;CONTRACTPL_DM.DIM_PL_CNTRCT_VER at(timestamp=&amp;gt; '2025-11-11 10:33:20'::timestamp_ltz) as contractVer join &lt;BR /&gt;CONTRACTPL_DM.LKP_PROGRAM at(timestamp=&amp;gt; '2025-11-11 10:33:20'::timestamp_ltz) as LKPPGM ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = &lt;BR /&gt;contractVer.DIM_PL_CNTRCT_VER_KEY where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM' order by &lt;BR /&gt;contractVer.DIM_PL_CNTRCT_VER_KEY ).&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 15:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979015#M46267</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-11-18T15:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a table using a with tablename as statement with a snow flake pass trough connecti</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979034#M46268</link>
      <description>&lt;P&gt;This Script works and it is a with table statment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET cn_SNOW = database=&amp;amp;databaseName.
SQL_FUNCTIONS=ALL
SERVER="&amp;amp;serverName."
SCHEMA=&amp;amp;schema.
AUTHDOMAIN=&amp;amp;authdomain.;

/************************* Defining some Time travel macro variables    ******************/

%let current_day=%sysfunc(today(), yymmdd10.);
%let now = %sysevalf(%sysfunc(time()) + 120);
%let current_time=%sysfunc(putn(&amp;amp;now., time.));
%put &amp;amp;=current_time &amp;amp;=current_day;

%let my_date_formatted = %sysfunc(intnx(day, %sysfunc(today()), -7), yymmdd10.);
%put &amp;amp;=my_date_formatted;

%let timestamp=at(timestamp=&amp;gt; %str(%')&amp;amp;my_date_formatted  &amp;amp;current_time%str(%')::timestamp_ltz);
%put &amp;amp;=timestamp;

proc sql;
connect to snow(&amp;amp;cn_SNOW.);     
 CREATE TABLE TEMP AS    
      select * from connection to snow 
     (
          WITH TEMPTBL as
          (
               select 	LKPPGM.*,
                         'O' as Affinity_Ind		

               from CONTRACTPL_DM.DIM_PL_CNTRCT_VER &amp;amp;timestamp. as contractVer 
               join CONTRACTPL_DM.LKP_PROGRAM &amp;amp;timestamp. as LKPPGM 
               ON LKPPGM.DIM_PL_CNTRCT_VER_KEY = contractVer.DIM_PL_CNTRCT_VER_KEY
               where LKPPGM.PROG_NM_CD='AFP' and LKPPGM.PROG_CAT_CD = 'INSBUSTRM'
               order by contractVer.DIM_PL_CNTRCT_VER_KEY
            )           
     
     select * from TEMPTBL

);
             
        disconnect from snow;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Nov 2025 18:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979034#M46268</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2025-11-18T18:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to create a table using a with tablename as statement with a snow flake pass trough connecti</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979051#M46269</link>
      <description>&lt;P&gt;Right.&amp;nbsp; The issue was that what you put inside the ( ) after the CONNECTION TO xxx needs to be a complete statement.&amp;nbsp; The same thing will apply to a statement passed using the EXECUTE BY xxx syntax.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Nov 2025 21:49:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-create-a-table-using-a-with-tablename-as-statement-with-a/m-p/979051#M46269</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-11-18T21:49:27Z</dc:date>
    </item>
  </channel>
</rss>

