<?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: Carriage Returns - and lines longer than 32,000 bytes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107160#M291822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might need to resort to processing the file byte by byte.&lt;/P&gt;&lt;P&gt;* UNTESTED CODE ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;infile "YOUR FILE" lrecl=1 recfm=n end=eof;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;file "NEW FILE" lrecl=1000000;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;nq=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do until (eof or (char='0A'X and mod(nq,2)=0) );&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input char $char1.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nq=nq+(char='"') ; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) and mod(nq)=1 then char=' ';&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put char $char1. @;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;put;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Feb 2013 21:48:24 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-02-12T21:48:24Z</dc:date>
    <item>
      <title>Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107159#M291821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all.&amp;nbsp; A while back I posted a question on how to remove CR / LF from csv files programatically, without the ability to use the options TERMSTR (as my file has both CR and LF and CR+LF all within given comments, so this option would still break the file at incorrect places).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The user Tom was very helpful and provided the code given below, which is extremely helpful for ALMOST all the files I need to process. The issue is that I have files in which the total records across one line are vastly longer than 32,000 bytes (dealing with comment data where one box can (and often is) over 10-20 thousand bytes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Beause of this, this process will not work on these files. Does anyone know if there is a way to alter this code, or another code that will work on these large text comment files?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom, if you are reading if you know a way that would be very helpful, and again thanks for this code below!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _null_;&lt;/P&gt;&lt;P&gt;infile "YOUR FILE" lrecl=32000 end=eof;&lt;/P&gt;&lt;P&gt;file "NEW FILE" lrecl=32000;&lt;/P&gt;&lt;P&gt;nq=0;&lt;/P&gt;&lt;P&gt;do until (mod(nq,2)=0 or eof);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _infile_ = TRANSLATE(_infile_,' ','0D0A'x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newn+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nq=nq+countc(_infile_,' " ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put _infile_ @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if mod(nq,2) then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; missq+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put ' ' @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;put;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Brandon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 17:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107159#M291821</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-02-12T17:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107160#M291822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might need to resort to processing the file byte by byte.&lt;/P&gt;&lt;P&gt;* UNTESTED CODE ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;infile "YOUR FILE" lrecl=1 recfm=n end=eof;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;file "NEW FILE" lrecl=1000000;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;nq=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do until (eof or (char='0A'X and mod(nq,2)=0) );&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input char $char1.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nq=nq+(char='"') ; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) and mod(nq)=1 then char=' ';&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put char $char1. @;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;put;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 21:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107160#M291822</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-12T21:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107161#M291823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Tom! Thanks again for helping me through this problem!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Okay so in your code, it works Great, with the exception that between every single line it puts an additional blank line.&amp;nbsp; Do you know why this portion is happening? (I changed the if char in ('OD'x,'OA'x) and &lt;STRONG&gt;mod(nq,2)=&lt;/STRONG&gt;1 portion and it ran exactly the way I was hoping, with this one minor detail.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the data looks like below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Colm1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Colm2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Colm3&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; So&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MUCH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TOM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; This&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;VERY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HELPFUL!&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 22:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107161#M291823</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-02-12T22:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107162#M291824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try removing the PUT statement after the END of the loop.&amp;nbsp; Most likely it is already putting the end of line and so the extra PUT is adding another end of line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 00:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107162#M291824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-13T00:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107163#M291825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello again Tom. I actually did try that, and it worked up until the file got to 1,000,000 bytes, and then the carriage returns stopped being processed. However with that put statement every line is 100% correct (there is just an extra line after the end of it). I believe that last put statement is resetting the lrecl somehow (or something along those lines). Does that make sense for the put statement to reset it because the loop reset and the lrecl reset to 1,000,000?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did have one "observation" and I was thinking maybe this is why it is not working. Please correct me if I am wrong!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyways, at the end of each line in my original file is a CRLF (the combination of the two). In the code above, since it is a do until, when it encounters the first CR ('OD'x) it is not triggered by the do Until,&amp;nbsp; thus it is written as normal (because its mod(q,2)=0). Then it gets to the LF, and it is written as normal (because the do until will still process through it). Therefore we are keeping our CR+LF at the end of every line, and then we are moving forward and putting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This results in a LF and then a CR+LF from the put statement. Would there be a way to test for subsetting values of CR+LF when the mod(nq,2)=0, and then completely remove that combination, thus when the put statement runs it fixes all of the problems?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or perhaps any other nifty ideas?&lt;/P&gt;&lt;P&gt;Again thanks for your help, I am learning a lot about the workings of SAS!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 01:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107163#M291825</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-02-13T01:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107164#M291826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I may have gotten it! Tom I took your code and added some modifications to it. If you have time, please see below and determine if there is anything incorrect in my logic. I will test it on more files to make sure the process works the way I intend it too (I feel the logic is solid, but I'm new at this!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I added a step that tests for CR and LF when they are outside of double quotes, and it removes them replacing them with null strings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore when it gets to the final LF at each line (in the CR+LF statement), it will replace it, however the put statement after the end clause will inherently put a new line, thus "replacing" the CR+LF at the end line with just the one LF that sas produces.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data _null_;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;infile "YOUR FILE" lrecl=1 recfm=n end=eof;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;file "NEW FILE" lrecl=1000000;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;nq=0;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;do until (eof or (char='0A'X and mod(nq,2)=0) );&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input char $char1.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nq=nq+(char='"') ; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) and mod(nq)=1 then char=' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) and mod(nq)=0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char=' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put char $char1. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put char $char1. @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;put;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 02:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107164#M291826</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-02-13T02:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107165#M291827</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do not change the value of CHAR to blank or else it will break the test for end of line that is in the condition of the DO UNTIL statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The extra PUT statement that you added inside the loop for when it sees a CR or LF while the quotes are balanced does not have a trailing @.&amp;nbsp; This is most likely what is added the blank line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to replace the CR and LF characters with spaces then you can eliminate a lot of the complexity and just do this after the number of quotes is incremented.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) then put ' ' @;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else put char $char1. @;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Or if you just want them to disappear then you can be even simpler :&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char not in ('0D'x,'0A'x) then put char $char1. @ ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;If your file is well formed such that only the LF at the end of the line is outside of the double quotes (and hence the only place where the number of quotes will be even) this should work.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;It will not matter if the files is on UNIX where the end of line is just the LF or on WINDOWS where the end of line is CR and LF.&amp;nbsp; If you prevent copying the CR and LF from the line to the output inside of the loop (either by writing a space or not writing anything) then the bare PUT statement at the end of the loop will write the end of line using the appropriate characters for your operating system.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;If your individual lines (in the fixed or new file) are longer than 1,000,000 characters (and if they are how the heck are you ever going to use them) then you might need to switch the settings on your output file to RECFM=N.&amp;nbsp; Then the PUT statement at the end should explicitly write the LF or CR and LF characters to end the line. (PUT '0D0A'X ; )&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 03:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107165#M291827</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-13T03:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107166#M291828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Tom. Just a few notes for clarification if you don't mind. The code that I provide above actually works and gives the exact output that I want (without the extra line). The original code posted is what gave the blank lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the code that I gave above,&amp;nbsp; (called code block 1 below), appears to do the exact same thing as the code that you noted with the "&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char not in ('0D'x,'0A'x) then put char $char1. @ ;" (named code block 2).&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt; &lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;However I&lt;/SPAN&gt;&lt;SPAN style="font-family: Arial;"&gt; see your point that when I change char to blank, the do until loop should no longer work (because char no longer equals '0A'x). It seems strange to me that the code I provided worked based upon this. Do you have any insights into why CODE BLOCK 1 works (and it does indeed work I tested it on 15 different files). &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt; &lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-family: Arial;"&gt;Thanks so much for your help, I am marking you as correct answer once again!&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt; &lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;CODE BLOCK 1&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;data _null_;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;infile "YOUR FILE" lrecl=1 recfm=n end=eof;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;file "NEW FILE" lrecl=1000000;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;nq=0;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;do until (eof or (char='0A'X and mod(nq,2)=0) );&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input char $char1.;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nq=nq+(char='"') ; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) and mod(nq)=1 then char=' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char in ('0D'x,'0A'x) and mod(nq)=0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char=' ';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put char $char1. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put char $char1. @;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;put;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CODE BLOCK 2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;data _null_;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;infile "YOUR FILE" lrecl=1 recfm=n end=eof;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;file "NEW FILE" lrecl=1000000;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;nq=0;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;do until (eof or (char='0A'X and mod(nq,2)=0) );&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input char $char1.;&lt;/P&gt;&lt;P style="background-color: #ffffff; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nq=nq+(char='"') ; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if char not in ('0D'x,'0A'x) then put char $char1. @;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;put;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 15:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107166#M291828</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-02-13T15:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Carriage Returns - and lines longer than 32,000 bytes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107167#M291829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;CODE BLOCK 1 is replacing all of the CR and LF with blanks.&amp;nbsp; BUT when it finds either when the quotes are balanced it spits out an end of line because of the PUT statement without a trailing @ . This would also explain your extra blank lines since if the lines do end with CR+LF (which is normal for Windows text files) then both of those characters will cause the put statement to write an end of line. If you look carefully the extra blank line should have a single space character from where the LF was converted to blank and the put.&amp;nbsp; Also the main DO loop that was designed to stop when it got to the end of line instead runs through the whole file.&amp;nbsp; I expected it to reach the end of the data step and execute the PUT statement so that there would be one extra blank line.&amp;nbsp; But instead it stops when the INPUT statement tries to read past the end of the file.&amp;nbsp; Perhaps it is because of using RECFM=F LRECL=1 on the input statement that the EOF variable is not working normally?&amp;nbsp; You should see this NOTE in the log:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;NOTE: Unexpected end of file for binary input.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CODE BLOCK 2 is removing all of the CR and LF characters, without replacing them with anything, but it is breaking out of the loop when it sees a LF that is not enclosed in quotes. Then the PUT statement at the end of the data step will write the end of line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try adding this line just before the RUN statement in both programs to see a note in the log every time the DO loop ends.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;putlog 'Interation number ' _n_ ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a simple two line TEST input file with an embedded CR in line one (column 17) and below are the resulting output files from the two versions of the code.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RULE:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----+----1----+----2----+----3----+----4----+----5----+----6----+&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1&amp;nbsp;&amp;nbsp; CHAR&amp;nbsp; 1,"This line is .split",3..2,"This line is not split",4.. 57&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZONE&amp;nbsp; 322566726666267207766722300322566726666267266727766722300&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMR&amp;nbsp; 1C248930C9E50930D30C942C3DA2C248930C9E50930EF4030C942C4DA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code Block 1 output&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RULE:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----+----1----+----2----+----3----+----4----+----5----+----6----+&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1&amp;nbsp;&amp;nbsp; CHAR&amp;nbsp; 1,"This line is&amp;nbsp; split",3 .. ..2,"This line is not split",4 .. .. 65&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZONE&amp;nbsp; 32256672666626722776672232002003225667266662672667277667223200200&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMR&amp;nbsp; 1C248930C9E50930030C942C30DA0DA2C248930C9E50930EF4030C942C40DA0DA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code Block 2 output&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RULE:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----+----1----+----2----+----3----+----4----+----5----+----6----+&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1&amp;nbsp;&amp;nbsp; CHAR&amp;nbsp; 1,"This line is split",3..2,"This line is not split",4.. 56&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZONE&amp;nbsp; 32256672666626727766722300322566726666267266727766722300&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NUMR&amp;nbsp; 1C248930C9E5093030C942C3DA2C248930C9E50930EF4030C942C4DA&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 01:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Carriage-Returns-and-lines-longer-than-32-000-bytes/m-p/107167#M291829</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-02-14T01:48:08Z</dc:date>
    </item>
  </channel>
</rss>

