<?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: Removing CR LF characters in an external file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700982#M214601</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/126332"&gt;@bhupeshpanwar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom. I knew I was doing something silly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly does sharedbuffers do? Will it help with the processing time if I intend to use it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It means that the locations in memory and the INFILE and FILE statements use to store the data being read/written to the disk are the same.&amp;nbsp; It could impove the performance.&amp;nbsp; But the risk is that if it doesn't work right you have corrupted the original file.&lt;/P&gt;
&lt;P&gt;If the file is not large (smaller than say 20 Gigabytes) then the performance increase is not worth the risk.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you posted will not work without using SHAREDBUFFERS because it it not explicitly re-writing each character. Use the modified code I posted instead.&lt;/P&gt;</description>
    <pubDate>Mon, 23 Nov 2020 17:22:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-11-23T17:22:35Z</dc:date>
    <item>
      <title>Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/698831#M213748</link>
      <description>&lt;P&gt;I have a pipe-delimited text file which has CR and LF characters within double quotes. This leads to issues when I am importing this file into SAS. I found a code that can remove unwanted characters from external file after reading it byte by byte. The file outputted is always 0 bytes and empty. I have pasted the code below. I have used this code successfully in the past but I think I am missing something this time. Need help!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let dsin= "X:\links.txt";&lt;BR /&gt;%let dsout="X:\output.txt";&lt;BR /&gt;%let repA=''; /* replacement character for LF */&lt;BR /&gt;%let repD=''; /* replacement character for CR */&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;BR /&gt;infile &amp;amp;dsin recfm=n sharebuffers;&lt;BR /&gt;file &amp;amp;dsout recfm=n;&lt;BR /&gt;input a $char1.;&lt;BR /&gt;retain open 0;&lt;BR /&gt;if a = '"' then open = ^(open);&lt;BR /&gt;if open then do;&lt;BR /&gt;if a = '0D'x then put &amp;amp;repD;&lt;BR /&gt;else if a = '0A'x then put &amp;amp;repA;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 22:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/698831#M213748</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-11-13T22:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/698838#M213750</link>
      <description>&lt;P&gt;That should work.&amp;nbsp; It will not remove the CR and LF but it should replace them with spaces.&lt;/P&gt;
&lt;P&gt;Show the log from your run.&amp;nbsp; I suspect that the input file was/is empty.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could remove the SHAREBUFFERS option and add back an explicit write of the other characters.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile &amp;amp;dsin recfm=n ;
  file &amp;amp;dsout recfm=n;
  input a $char1.;
  retain open 0;
  if a = '"' then open = ^(open);
  if open then do;
    if a = '0D'x then a=&amp;amp;repD;
    else if a = '0A'x then a=&amp;amp;repA;
  end;
  put a $char1.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Plus without the SHAREDBUFFERS you could actually remove either the CR or LF character or both.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if a = '0D'x then delete;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 Nov 2020 00:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/698838#M213750</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-14T00:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/698867#M213768</link>
      <description>Better post some sample data, so we can test the code for you .</description>
      <pubDate>Sat, 14 Nov 2020 11:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/698867#M213768</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-14T11:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700961#M214592</link>
      <description>&lt;P&gt;I apologize for the delay as I got caught up with something else.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the sample data file and the output file being generated. As you would see that this is not the expected output. I am also pasting the log. What am I missing here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;========LOG ================&lt;/P&gt;&lt;P&gt;47650 /* Fixing CR LF */&lt;BR /&gt;47651 %let dsin= "X:\studies.txt";&lt;BR /&gt;47652 %let dsout="X:\links.txt";&lt;BR /&gt;47653 %let repA=''; /* replacement character for LF */&lt;BR /&gt;47654 %let repD=''; /* replacement character for CR */&lt;BR /&gt;47655 data _null_;&lt;BR /&gt;47656 infile &amp;amp;dsin recfm=n ;&lt;BR /&gt;47657 file &amp;amp;dsout recfm=n;&lt;BR /&gt;47658 input a $char1.;&lt;BR /&gt;47659 retain open 0;&lt;BR /&gt;47660 if a = '"' then open = ^(open);&lt;BR /&gt;47661 if open then do;&lt;BR /&gt;47662 if a = '0D'x then put &amp;amp;repD;&lt;BR /&gt;47663 else if a = '0A'x then put &amp;amp;repA;&lt;BR /&gt;47664 end;&lt;BR /&gt;47665 run;&lt;/P&gt;&lt;P&gt;NOTE: UNBUFFERED is the default with RECFM=N.&lt;BR /&gt;NOTE: The infile "X:\studies.txt" is:&lt;BR /&gt;Filename=X:\studies.txt,&lt;BR /&gt;RECFM=N,LRECL=256,File Size (bytes)=2100,&lt;BR /&gt;Last Modified=23Nov2020:10:11:32,&lt;BR /&gt;Create Time=23Nov2020:10:05:28&lt;/P&gt;&lt;P&gt;NOTE: UNBUFFERED is the default with RECFM=N.&lt;BR /&gt;NOTE: The file "X:\links.txt" is:&lt;BR /&gt;Filename=X:\links.txt,&lt;BR /&gt;RECFM=N,LRECL=256,File Size (bytes)=0,&lt;BR /&gt;Last Modified=23Nov2020:10:18:15,&lt;BR /&gt;Create Time=23Nov2020:10:11:59&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.00 seconds&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 16:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700961#M214592</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-11-23T16:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700970#M214593</link>
      <description>&lt;P&gt;If you want to use sharedbuffers then the input and output files have to be the same file.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 16:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700970#M214593</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-23T16:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700973#M214596</link>
      <description>&lt;P&gt;Thanks Tom. I knew I was doing something silly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What exactly does sharedbuffers do? Will it help with the processing time if I intend to use it?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 16:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700973#M214596</guid>
      <dc:creator>bhupeshpanwar</dc:creator>
      <dc:date>2020-11-23T16:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Removing CR LF characters in an external file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700982#M214601</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/126332"&gt;@bhupeshpanwar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom. I knew I was doing something silly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly does sharedbuffers do? Will it help with the processing time if I intend to use it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It means that the locations in memory and the INFILE and FILE statements use to store the data being read/written to the disk are the same.&amp;nbsp; It could impove the performance.&amp;nbsp; But the risk is that if it doesn't work right you have corrupted the original file.&lt;/P&gt;
&lt;P&gt;If the file is not large (smaller than say 20 Gigabytes) then the performance increase is not worth the risk.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you posted will not work without using SHAREDBUFFERS because it it not explicitly re-writing each character. Use the modified code I posted instead.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 17:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-CR-LF-characters-in-an-external-file/m-p/700982#M214601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-23T17:22:35Z</dc:date>
    </item>
  </channel>
</rss>

