<?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: Inserting code from a text file into pass-through SQL or into a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-code-from-a-text-file-into-pass-through-SQL-or-into-a/m-p/915753#M360806</link>
    <description>&lt;P&gt;You didn't include the beginning&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;EXECUTE
   (CREATE OR REPLACE TABLE ADS_DAT.SASUSR.ORDSP AS
    SELECT XR.CUST_INDIV_ID&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;of the code, or the end of the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  FROM  XREF_TBL XR
  INNER JOIN EDW_PROD.CONSUM_EDS.V_EDS_ORDER_HEADER OH  ON XR.CUST_ORDER_NBR = OH.CUST_ORDER_NBR AND XR.CUST_INDIV_ID = OH.CUST_INDIV_ID
 GROUP BY XR.CUST_INDIV_ID
   ) BY SNFLAADS ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just fix that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
   file code;
   infile   
  if _n_=1 then put 
  'EXECUTE BY SNFLAADS'
/ '(CREATE OR REPLACE TABLE ADS_DAT.SASUSR.ORDSP AS'
/ ' SELECT XR.CUST_INDIV_ID'
  ;
  infile "/emdata/ADS_Data/BbB/temp/ordspim_code.txt" end=eof;
  input;
  put _infile_;
  if eof then put
  'FROM  XREF_TBL XR'
/ '  INNER JOIN EDW_PROD.CONSUM_EDS.V_EDS_ORDER_HEADER OH '
/ '   ON XR.CUST_ORDER_NBR = OH.CUST_ORDER_NBR'
/ '   AND XR.CUST_INDIV_ID = OH.CUST_INDIV_ID'
/ '  GROUP BY XR.CUST_INDIV_ID'
/ ');'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then include this SAS code with the %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Feb 2024 03:38:59 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-02-13T03:38:59Z</dc:date>
    <item>
      <title>Inserting code from a text file into pass-through SQL or into a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-code-from-a-text-file-into-pass-through-SQL-or-into-a/m-p/915671#M360785</link>
      <description>&lt;P&gt;I have a SAS program that uses a DO LOOP to generate about 4,000 lines of code that I then export to a text file.&amp;nbsp; I want to bring that code into pass-through SQL to query tables on Snowflake.&amp;nbsp; How do I do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If i were coding entirely in SAS, it would be easy.&amp;nbsp; I would just use&amp;nbsp; %INCLUDE.&amp;nbsp; But apparently that does not work in pass-through SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the relevant code (that doesn't work):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC EXPORT DATA=PIMCODE &lt;BR /&gt;OUTFILE="/emdata/ADS_Data/BbB/temp/ordspim_code.txt" &lt;BR /&gt;DBMS=TAB REPLACE ;&lt;BR /&gt;PUTNAMES=NO ;&lt;BR /&gt;RUN ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;PROC SQL ; &amp;amp;CONNECTTOADS ;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;EXECUTE&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;(CREATE OR REPLACE TABLE ADS_DAT.SASUSR.ORDSP AS&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp; SELECT&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; XR.CUST_INDIV_ID&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; %INCLUDE("/emdata/ADS_Data/BbB/temp/ordspim_code.txt");&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; FROM&amp;nbsp; XREF_TBL XR&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; INNER JOIN EDW_PROD.CONSUM_EDS.V_EDS_ORDER_HEADER OH&amp;nbsp; ON XR.CUST_ORDER_NBR = OH.CUST_ORDER_NBR AND XR.CUST_INDIV_ID = OH.CUST_INDIV_ID&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;GROUP BY XR.CUST_INDIV_ID&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; &amp;nbsp;) BY SNFLAADS ;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;DISCONNECT FROM SNFLAADS; QUIT;&lt;/DIV&gt;</description>
      <pubDate>Mon, 12 Feb 2024 20:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-code-from-a-text-file-into-pass-through-SQL-or-into-a/m-p/915671#M360785</guid>
      <dc:creator>bbenbaruch</dc:creator>
      <dc:date>2024-02-12T20:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting code from a text file into pass-through SQL or into a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-code-from-a-text-file-into-pass-through-SQL-or-into-a/m-p/915753#M360806</link>
      <description>&lt;P&gt;You didn't include the beginning&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;EXECUTE
   (CREATE OR REPLACE TABLE ADS_DAT.SASUSR.ORDSP AS
    SELECT XR.CUST_INDIV_ID&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;of the code, or the end of the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  FROM  XREF_TBL XR
  INNER JOIN EDW_PROD.CONSUM_EDS.V_EDS_ORDER_HEADER OH  ON XR.CUST_ORDER_NBR = OH.CUST_ORDER_NBR AND XR.CUST_INDIV_ID = OH.CUST_INDIV_ID
 GROUP BY XR.CUST_INDIV_ID
   ) BY SNFLAADS ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just fix that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
   file code;
   infile   
  if _n_=1 then put 
  'EXECUTE BY SNFLAADS'
/ '(CREATE OR REPLACE TABLE ADS_DAT.SASUSR.ORDSP AS'
/ ' SELECT XR.CUST_INDIV_ID'
  ;
  infile "/emdata/ADS_Data/BbB/temp/ordspim_code.txt" end=eof;
  input;
  put _infile_;
  if eof then put
  'FROM  XREF_TBL XR'
/ '  INNER JOIN EDW_PROD.CONSUM_EDS.V_EDS_ORDER_HEADER OH '
/ '   ON XR.CUST_ORDER_NBR = OH.CUST_ORDER_NBR'
/ '   AND XR.CUST_INDIV_ID = OH.CUST_INDIV_ID'
/ '  GROUP BY XR.CUST_INDIV_ID'
/ ');'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then include this SAS code with the %INCLUDE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 03:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-code-from-a-text-file-into-pass-through-SQL-or-into-a/m-p/915753#M360806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-13T03:38:59Z</dc:date>
    </item>
  </channel>
</rss>

