<?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: Exporting to Text using 2-character delimiters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939962#M369013</link>
    <description>&lt;P&gt;Are the users TYPING the text files?&amp;nbsp; If not then it should not matter if the text contains the delimiter character because a properly created delimited text file will have quotes added around values that contain the delimiter character (or the quote character).&amp;nbsp; Find out what tool they are using to make the file and make sure they use it in a way that make files that can be parsed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there is no need to use PROC EXPORT to make a delimited text file from a dataset.&amp;nbsp; All it will do is write a data step for you.&amp;nbsp; So just write the data step yourself.&amp;nbsp; Then you can use the DLMSTR= option on the FILE statement if you did want to insert some goofy multiple character delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class(obs=3);
  file txt dlmstr='||';
  put (_all_) (+0) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to make a header row then do that first and then append the data lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class(obs=0) out=names;
  var _all_;
run;

data _null_;
  set names ;
  file txt dlmstr='||';
  put _name_ @ ;
run;

data _null_;
  set sashelp.class(obs=3);
  file txt mod dlmstr='||';
  put (_all_) (+0) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Name||Sex||Age||Height||Weight
Alfred||M||14||69||112.5
Alice||F||13||56.5||84
Barbara||F||13||65.3||98
&lt;/PRE&gt;</description>
    <pubDate>Mon, 19 Aug 2024 18:12:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-08-19T18:12:35Z</dc:date>
    <item>
      <title>Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939944#M369006</link>
      <description>&lt;P&gt;Is there a way to use PROC Export to export a data set to a delimited text file using a custom 2 character delimiter?&amp;nbsp; My data includes a text field with long entries made by users, and frankly I am afraid that one day someone will have a delimiter in their text and throw off everything.&amp;nbsp; It's happened before.&amp;nbsp; I am using pipe (|) now, and it works for the time being.&amp;nbsp; But, in the long run I'd prefer to use something like |# as the delimiter.&amp;nbsp; I read online that Export does not support DLMSTR which is what this would require, as only the first row has double delimiters when I try using DBMS=DLM.&amp;nbsp;&amp;nbsp; Is there another &lt;EM&gt;programmatic &lt;/EM&gt;way around this?&amp;nbsp; I'd prefer not to use the File menu.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully, a future update will add dbms=DLMSTR to Proc Export.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 17:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939944#M369006</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-08-19T17:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939949#M369010</link>
      <description>&lt;P&gt;How about using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n15o12lpyoe4gfn1y1vcp6xs6966.htm" target="_self"&gt;File Statement&lt;/A&gt; in the Data step? The File Statement accepts a&amp;nbsp;'&lt;EM class="xisDoc-userSuppliedValue"&gt;list-of-delimiting-characters&lt;/EM&gt;' as delimiter on the Delimiter Option.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2024 17:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939949#M369010</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-08-19T17:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939950#M369011</link>
      <description>Yes, I've only used that for importing.  I can understand how it works for exporting to Workbooks, but I am going to have to really dig into the weeds to see how to use it for exporting to text.</description>
      <pubDate>Mon, 19 Aug 2024 17:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939950#M369011</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-08-19T17:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939961#M369012</link>
      <description>&lt;P&gt;Try something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set sashelp.class;
   file 'yourpath/class.txt' dlmstr='|#';
   put name age sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2024 18:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939961#M369012</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-08-19T18:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939962#M369013</link>
      <description>&lt;P&gt;Are the users TYPING the text files?&amp;nbsp; If not then it should not matter if the text contains the delimiter character because a properly created delimited text file will have quotes added around values that contain the delimiter character (or the quote character).&amp;nbsp; Find out what tool they are using to make the file and make sure they use it in a way that make files that can be parsed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that there is no need to use PROC EXPORT to make a delimited text file from a dataset.&amp;nbsp; All it will do is write a data step for you.&amp;nbsp; So just write the data step yourself.&amp;nbsp; Then you can use the DLMSTR= option on the FILE statement if you did want to insert some goofy multiple character delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set sashelp.class(obs=3);
  file txt dlmstr='||';
  put (_all_) (+0) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to make a header row then do that first and then append the data lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=sashelp.class(obs=0) out=names;
  var _all_;
run;

data _null_;
  set names ;
  file txt dlmstr='||';
  put _name_ @ ;
run;

data _null_;
  set sashelp.class(obs=3);
  file txt mod dlmstr='||';
  put (_all_) (+0) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Name||Sex||Age||Height||Weight
Alfred||M||14||69||112.5
Alice||F||13||56.5||84
Barbara||F||13||65.3||98
&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2024 18:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/939962#M369013</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-19T18:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940072#M369047</link>
      <description>Thanks.  I will try both solutions here and see.  The open text field I have in my data is ...TOO open (I'm not the one who set up the system which collects and stores this data, so it's out of my control). It does include some quotes in a few cases, which would throw off my data if I tried to enclose the text with quotes, been there done that.  That's why I am resorting to goofy double delimiters.</description>
      <pubDate>Tue, 20 Aug 2024 11:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940072#M369047</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-08-20T11:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940088#M369048</link>
      <description>&lt;P&gt;The main thing that can mess up using delimited text files with SAS are embedded end of line markers.&amp;nbsp; You can fix that by making sure that you use CRLF as the end of line marker and remove/replace any CRLF pairs from the text fields.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data clean ;
  set have;
  array _char_ _character_;
  do over _char_;
    _char_=tranwrd(_char_,'0D0A'x,'0D'x);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can test if the resulting file can be written out and re-read with something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
data _null_;
  set clearn;
  file csv dsd termstr=crlf lrecl=1000000;
  put (_all_) (+0);
run;
data test;
  infile csv dsd termstr=crlf truncover lrecl=1000000;
  if 0 then set clean;
  input (_all_) (+0);
run;
proc compare data=test compare=clean;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The only other rare thing that will confuse SAS reading of delimited files is the presence of two fields in the same observations that have the earlier one starting with single quote and the later one ending with single quote. This can cause a line that looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;val1,'val2,val3,val4',val5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which SAS will read as three values instead of five when trying to read it because it will treat the single quotes around a value the same as it does double quotes around a value.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2024 12:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940088#M369048</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-08-20T12:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940098#M369050</link>
      <description>&lt;P&gt;That works. I just needed to add the replace option after the delimiter. like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set sashelp.class;
   file 'yourpath/class.txt' dlmstr='|#'; replace;
   put name age sex;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Aug 2024 14:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940098#M369050</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-08-20T14:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to Text using 2-character delimiters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940101#M369051</link>
      <description>&lt;P&gt;As well as add the column headings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set sashelp.class;
   file 'yourpath/class.txt' dlmstr='|#'; replace;
if _n_ = 1 then do;
   put "name" '|#' "age" '|#' "sex";
end;
if _n_ &amp;gt; 1 then do;
put name age sex;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Aug 2024 14:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-to-Text-using-2-character-delimiters/m-p/940101#M369051</guid>
      <dc:creator>RandoDando</dc:creator>
      <dc:date>2024-08-20T14:27:19Z</dc:date>
    </item>
  </channel>
</rss>

