<?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: Escape character in data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672910#M202302</link>
    <description>&lt;P&gt;Reading between the lines are your post it sounds like you are extracting data from some source (external database perhaps?) and want to process it in SAS and then create a new text file you can load into some target (the same or another external database).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many databases use Unix style "escape" characters instead of quoting to protect delimiters in delimited data files.&amp;nbsp; SAS does not directly support that style.&amp;nbsp;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should first check if your source and target system can work with NORMAL delimited files that follow basic&amp;nbsp;&lt;A href="https://tools.ietf.org/html/rfc4180" target="_self"&gt;RFC-4180&lt;/A&gt;&amp;nbsp;standards.&amp;nbsp; Using that will not only make it easier to use the text files with SAS it will also make them compatible with other software.&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jul 2020 16:26:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-07-28T16:26:03Z</dc:date>
    <item>
      <title>Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672900#M202293</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the source extraction ,we are getting character like pipe &amp;amp; escape character and when we are loading into the destination db ,its causing an issue. We are extracting the data in a work dataset and then exporting into the .txt file and then loading into db separately&amp;nbsp; via external table load in db2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have thought to enclose double quotes or introduce a&amp;nbsp; escape char , if we face any such situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whenever we have pipe value and did proc export, then SAS automatically enclose the column value with double quotes, which is good.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if we have escape character, then how to introduce double quotes or another escape character to that column please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let us know. Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 15:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672900#M202293</guid>
      <dc:creator>helannivas88</dc:creator>
      <dc:date>2020-07-28T15:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672905#M202298</link>
      <description>&lt;P&gt;Please show us what you are seeing&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 15:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672905#M202298</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-28T15:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672908#M202300</link>
      <description>&lt;P&gt;While exporting, we are using pipe delimiter, so in the .txt file we have got below like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;246503|Y|"51 |THE FARMER"|USA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;51 |THE FARMER is a single value and that has been enclosed with double quoted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for the escape characters, we have value like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;34604136|QUTE|WRB|ABB PARTNERSHIP\REG SRD\AB&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We need&amp;nbsp;ABB PARTNERSHIP\REG SRD\AB to be enclosed with double quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 16:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672908#M202300</guid>
      <dc:creator>helannivas88</dc:creator>
      <dc:date>2020-07-28T16:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672909#M202301</link>
      <description>&lt;P&gt;How are you exporting? Can you show us the code?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 16:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672909#M202301</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-28T16:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672910#M202302</link>
      <description>&lt;P&gt;Reading between the lines are your post it sounds like you are extracting data from some source (external database perhaps?) and want to process it in SAS and then create a new text file you can load into some target (the same or another external database).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many databases use Unix style "escape" characters instead of quoting to protect delimiters in delimited data files.&amp;nbsp; SAS does not directly support that style.&amp;nbsp;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should first check if your source and target system can work with NORMAL delimited files that follow basic&amp;nbsp;&lt;A href="https://tools.ietf.org/html/rfc4180" target="_self"&gt;RFC-4180&lt;/A&gt;&amp;nbsp;standards.&amp;nbsp; Using that will not only make it easier to use the text files with SAS it will also make them compatible with other software.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 16:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672910#M202302</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-28T16:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672911#M202303</link>
      <description>&lt;P&gt;So you need to force quoting of values that contain a backslash?&lt;/P&gt;
&lt;P&gt;Why?&lt;/P&gt;
&lt;P&gt;Can't the system that is reading the file disable treating \ as a special character?&lt;/P&gt;
&lt;P&gt;If not could you instead convert the \ to \\ to "escape" it?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 16:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672911#M202303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-28T16:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672913#M202304</link>
      <description>&lt;P&gt;proc export data=work.TEMP_TEST&lt;BR /&gt;outfile=/shared/data/Test/ABC.txt&lt;BR /&gt;dbms=dlm replace;&lt;BR /&gt;PUTNAMES=NO;&lt;BR /&gt;delimiter='|';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 16:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672913#M202304</guid>
      <dc:creator>helannivas88</dc:creator>
      <dc:date>2020-07-28T16:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672916#M202306</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/182470"&gt;@helannivas88&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;proc export data=work.TEMP_TEST&lt;BR /&gt;outfile=/shared/data/Test/ABC.txt&lt;BR /&gt;dbms=dlm replace;&lt;BR /&gt;PUTNAMES=NO;&lt;BR /&gt;delimiter='|';&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that a faster way to do that is to just use a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set work.TEMP_TEST;
   file "/shared/data/Test/ABC.txt" dsd dlm='|' ;
   put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But that wouldn't actually change the values written.&amp;nbsp; But as long as your character values are long enough to hold the extra "escape" characters you could pre-process the data to add them.&amp;nbsp; For example to convert all of the backslashes to double backslashes you could use TRANWRD() function call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set work.TEMP_TEST;
   file "/shared/data/Test/ABC.txt" dsd dlm='|' ;
   array _c _character_;
   do over _c;
     _c=tranwrd(_c,'\','\\');
   end;
   put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jul 2020 17:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672916#M202306</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-28T17:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Escape character in data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672928#M202311</link>
      <description>&lt;P&gt;Please show the code you are using to "export" into a txt file.&lt;/P&gt;
&lt;P&gt;Then show a few lines of that exported text file. Copy from the text file using a plain text viewer or editor, NOT a word processing program, database, html or other viewer. Paste into a code box opened on the forum with the &amp;lt;/&amp;gt; icon. The message windows here will reformat pasted text, introducing html characters, change blank space and otherwise rending the text different than is actually in the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is also best to post the code from the log that generates the output the same way.&lt;/P&gt;
&lt;P&gt;It may also be a good idea to show how you bring the data into SAS.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 17:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Escape-character-in-data-step/m-p/672928#M202311</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-07-28T17:43:54Z</dc:date>
    </item>
  </channel>
</rss>

