<?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: Need to extract SQL code from a .txt file and store it in a string variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782564#M249477</link>
    <description>&lt;P&gt;You are creating the value in a dataset variable, but since you are using _NULL_ dataset it is not being written anywhere.&amp;nbsp; If you want to store it in a macro variable then you need to add a CALL SYMPUTX() function call. Use the LAST variable you created with the INFILE statement to know when to create the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DMLSTR= option is doing nothing in your data step.&amp;nbsp; Are you trying to remove end-of-line comments that are marked with // ?&amp;nbsp; If so then try reading the line into a variable instead of using the _INFILE_ automatic variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length sql line $32767;
  retain sql ;
  infile msghtml flowover dlmstr='//' end=last;
  input line ;
  sql = catx(' ',sql,line);
  if last then call symputx('sql',sql);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 26 Nov 2021 16:40:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-11-26T16:40:35Z</dc:date>
    <item>
      <title>Need to extract SQL code from a .txt file and store it in a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782562#M249475</link>
      <description>&lt;DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Hello - I'm brand new to SAS and am struggling with something. I have SQL code stored in a .txt file. I would like to read the .txt file contents into a single string variable in SAS that can then be called in a PROC SQL statement in order to run a query. The .txt file does have a few parameters/variables inside it that I will need to replace once imported into SAS, but I'm able to do that successfully. Below is a sample of the code I'm currently using. This process is able to get the .txt file contents, but it concatenates the lines in a way that makes the query error out due to formatting issues. Any point in the right direction is greatly appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;CODE class=""&gt;FILENAME msghtml "//mypath/myfile.txt"
data _null_;
length text $32767;
retain text '';
infile msghtml flowover dlmstr='//' end=last;
input;
text = catx(text,_infile);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 26 Nov 2021 16:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782562#M249475</guid>
      <dc:creator>kazoli</dc:creator>
      <dc:date>2021-11-26T16:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Need to extract SQL code from a .txt file and store it in a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782564#M249477</link>
      <description>&lt;P&gt;You are creating the value in a dataset variable, but since you are using _NULL_ dataset it is not being written anywhere.&amp;nbsp; If you want to store it in a macro variable then you need to add a CALL SYMPUTX() function call. Use the LAST variable you created with the INFILE statement to know when to create the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The DMLSTR= option is doing nothing in your data step.&amp;nbsp; Are you trying to remove end-of-line comments that are marked with // ?&amp;nbsp; If so then try reading the line into a variable instead of using the _INFILE_ automatic variable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length sql line $32767;
  retain sql ;
  infile msghtml flowover dlmstr='//' end=last;
  input line ;
  sql = catx(' ',sql,line);
  if last then call symputx('sql',sql);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Nov 2021 16:40:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782564#M249477</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-26T16:40:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need to extract SQL code from a .txt file and store it in a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782582#M249491</link>
      <description>&lt;P&gt;Perfect, that did the trick - thank you very much! I found a lot of this code elsewhere and tried to apply it to my case, but this has taught me more in this area. Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 19:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-extract-SQL-code-from-a-txt-file-and-store-it-in-a/m-p/782582#M249491</guid>
      <dc:creator>kazoli</dc:creator>
      <dc:date>2021-11-26T19:05:19Z</dc:date>
    </item>
  </channel>
</rss>

