<?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 Removing embedded carriage returns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378734#M276820</link>
    <description>&lt;P&gt;I have a data set that has quite a few carriage returns. I need a way to write this into sas and not change my initial data. The initial data step that I had was:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; companyinfo;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'sample.csv'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lrecl&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2500&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;firstobs&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dsd&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR1:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$3.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR2:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$11.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR3:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$50.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;VAR4 VAR5:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR6:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR7:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$550.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;VAR8 VAR9:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$1.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;VAR10:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$3.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Where VAR7 is the column that contains CR. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;I tried termstr=crlf and var7=tranwrd(var7,'0D'x,'') amd have not been able to find a correct result. &lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jul 2017 15:55:48 GMT</pubDate>
    <dc:creator>Wmcfarland</dc:creator>
    <dc:date>2017-07-24T15:55:48Z</dc:date>
    <item>
      <title>Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378734#M276820</link>
      <description>&lt;P&gt;I have a data set that has quite a few carriage returns. I need a way to write this into sas and not change my initial data. The initial data step that I had was:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; companyinfo;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="2"&gt;'sample.csv'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;lrecl&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2500&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;firstobs&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dsd&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR1:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$3.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR2:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$11.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR3:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$50.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;VAR4 VAR5:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR6:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; VAR7:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$550.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;VAR8 VAR9:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$1.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;VAR10:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$3.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Where VAR7 is the column that contains CR. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;I tried termstr=crlf and var7=tranwrd(var7,'0D'x,'') amd have not been able to find a correct result. &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 15:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378734#M276820</guid>
      <dc:creator>Wmcfarland</dc:creator>
      <dc:date>2017-07-24T15:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378739#M276821</link>
      <description>&lt;P&gt;You were very close to the solution.&lt;/P&gt;
&lt;P&gt;Change line:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var7=tranwrd(var7,'0D'x,'');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;into:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var7 = translate(var7,' ','0D'x);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 16:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378739#M276821</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-24T16:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378747#M276822</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;That appears to give me the right number of observations but the information after the CR appears to be deleted and it is giving me errors for the fields that follow VAR7. &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 17:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378747#M276822</guid>
      <dc:creator>Wmcfarland</dc:creator>
      <dc:date>2017-07-24T17:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378751#M276823</link>
      <description>&lt;P&gt;Please post:&lt;/P&gt;
&lt;P&gt;(1) the log of your run&lt;/P&gt;
&lt;P&gt;(2) your output and your expected output for a specific problamatic row&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without this info I cannot guess what is the problem.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 17:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378751#M276823</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-24T17:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378752#M276824</link>
      <description>&lt;P&gt;I think the general approach has been to read in the full line using _infile_ and either write it out without the carriage return using Compress and then import that file, or to process line afterwards manually using SCAN.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 17:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378752#M276824</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-24T17:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378761#M276825</link>
      <description>&lt;P&gt;&amp;nbsp;Are you sure that the embedded line breaks are using the exact same character strings as the normal line breaks? &amp;nbsp;Have you read the data using an editor that shows the underlying data? or with a SAS data step using fixed mode input so that you can see the actual characters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could use the code to look at the first 1,000 characters in your file. &amp;nbsp;If that includes a line with extra line break embedded in VAR7 then you can tell if it is using the same hexcodes as at the end of record. &amp;nbsp;(You could play with OBS= and FIRSTOBS= options to read other parts of the file of it is large.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_:
  infile 'sample.csv' lrecl=100 recfm=f obs=10;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's assume that they are both using the same codes and so the INFILE statement will have no way to tell the false line breaks form the real ones so that you need to do something to make it possible to read this data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the values really never have the delimters in the data then you could just count the number of fields and eliminate line breaks when there are not enough fields. But using comma as the delimiter and having many long character variables it is very likely this approach will not work since it is probably likely that some of those variables will contain commas. &amp;nbsp;But you could try it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename fixedcsv temp;
data _null_;
  infile 'sample.csv' lrecl=2500;
  file fixedcsv lrecl=5000 ;
  input ;
  put _infile_ @;
  if countw(_infile_,',','qm') &amp;lt; 10 then do;
    input ;
    put _infile_ @;
  end;
  put;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if that doesn't make a file you can read then if the values that have the embedded line breaks are quoted then you can at least fix the value by counting the number of quote characters you see and keeping track if you have seen an even or an odd number. Then replace any linebreaks you see when there are an odd number of quotes with something else. &amp;nbsp;So you could replace any quoted CR or LF with a vertical bar for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename fixedcsv temp;
data _null_;
  infile 'sample.csv' recfm=n ;
  file fixedcsv recfm=n;
  retain quoted 0 quote '"';
  input ch $char1. ;
  if ch=quote then quoted = mod(quoted+(ch=quote),2);
  if ch in ('0D'x,'0A'x) and quoted then put '|' ;
  else put ch $char1.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have a fixed version of the data in the temporary file then read that into a dataset using data step like you posted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data companyinfo;
  infile fixedcsv lrecl=5000 firstobs=2 dsd truncover;
  length var1 $3 var2 $11 var3 $50 var4 8 var5 $2 
         var6 $2 var7 $550 var8 8 var9 $1 var10 $3
  ;
  input var1-var10;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Moderator note: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/621023/highlight/true#M276834" target="_self"&gt;see also the code/macro provided&lt;/A&gt; by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28909"&gt;@AllanBowe&lt;/a&gt;&amp;nbsp;to solve this as a general case.&lt;/EM&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Mon, 05 Sep 2022 19:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378761#M276825</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-05T19:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378762#M276826</link>
      <description>&lt;P&gt;I would like to extend&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s post. Assuming the problem is only in var7 -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please run next code and post the log (results):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
  set have;
        length check $500;
        check = compress(var7,' ','ADFI');
        if length(check) &amp;gt; 1 then do;
            m+1;
            if m &amp;lt; 20 then put _N_= ' *' check=  '*' /&lt;BR /&gt;                check= $hex100. ;
        end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the log will enable check non visible characters by displaying its hex value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 18:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378762#M276826</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-07-24T18:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378767#M276827</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree with Reeza.&lt;/P&gt;
&lt;P&gt;You can use the&amp;nbsp;$VARYINGw. informat when&amp;nbsp;reading the full line into a variable (VarFullLine).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
   infile file-specification length=reclen;
   input @;
   fwidth=reclen-9;
   input id_name $ 1-9
         @10 VarFullLine $varying750. fwidth;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use the TRANSTRN function instead of the TRANWRD function.&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-comparisons"&gt;
&lt;DIV id="n03cveuig7ivoin1e9es59q9z4df" class="xis-paragraph"&gt;The TRANWRD function differs from the TRANSTRN function because TRANSTRN allows the replacement string to have a length of zero. TRANWRD uses a single blank instead when the replacement string has a length of zero.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use the compress function and indicate the list of characters you want to keep.&lt;/P&gt;
&lt;P&gt;example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
 source='aZer§#t_y';
 y=compress(source, '+-', 'kin');
 /*   k for keep (instead of remove), i for case insensitive, l for lowercase, u for uppercase 
    , n for digits (and underscore character and English letters!), p for punctuation marks 
    , w for "write-able"  */
 put y=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or simply compress the&amp;nbsp;control characters&lt;/P&gt;
&lt;P&gt;compress(source, , "c"); /* remove control characters from the result */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other functions that you might find interesting with regard to control characters (carriage return, line feed, form feed, page break ...)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;( carriage returns (‘0D’x ), line feeds (‘0A’x) -&amp;gt; hexadecimal constant notation &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;ANYALPHA, NOTALPHA&lt;/P&gt;
&lt;P&gt;, ANYDIGIT, NOTDIGIT&lt;/P&gt;
&lt;P&gt;, ANYPRINT, NOTPRINT&lt;/P&gt;
&lt;P&gt;, TRANSLATE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Terminate by using the scan function to make your variables!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See also this interesting usage note:&lt;/P&gt;
&lt;P&gt;Usage Note 14178: The INFILE statement TERMSTR= option facilitates reading files between UNIX and Windows&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/14/178.html" target="_blank"&gt;http://support.sas.com/kb/14/178.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 18:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378767#M276827</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2017-07-24T18:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378808#M276828</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154398"&gt;@Wmcfarland&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The following not tested code (you haven't provided&amp;nbsp;sample data) should replace all whitespace characters in your source with a blank before reading the data into SAS variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data companyinfo;
  infile 'sample.csv' lrecl=2500 firstobs=2 dsd truncover;
  /* read source record into input buffer; @: holds line, next input will not read a new line */
  input @;
  /* replace all whitespace characters in input buffer with a blank */
  _infile_=prxchange('s/\s/ /oi',-1,trim(_infile_));
  /* map variables agains input buffer; due to @ before this input statement will not read a new record */
  input VAR1:$3. VAR2:$11. VAR3:$50. VAR4 VAR5:$2. VAR6:$2. VAR7:$550. VAR8 VAR9:$1.
    VAR10:$3.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 21:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378808#M276828</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-24T21:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378809#M276829</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;How is that code supposed to change end of line characters that are in appropriately placed in the middle of a record?&lt;/P&gt;
&lt;P&gt;That could would just read such records are two different records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 21:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378809#M276829</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-24T21:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378810#M276830</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The OP uses a .csv and I've made the assumption that we're simply dealing the normal embedded LF problem but that a records ends with CRLF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154398"&gt;@Wmcfarland&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Please post your&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;sample.csv&lt;/EM&gt; as attachment so we can deal with the real thing and stop with all the guesswork.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 22:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378810#M276830</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-24T22:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378820#M276831</link>
      <description>&lt;P&gt;You have another problem that you are not describing it seems.&lt;/P&gt;
&lt;P&gt;The solution given works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'test.csv' lrecl=2500  dlm=',';
  VAR1='abc';VAR2='def';VAR3=' ';VAR4=VAR5=VAR8;VAR6=' ';VAR7='ghi'||'0D'x||'jkl';VAR9='m';VAR10='n';
  put / VAR1-VAR10 ;
run;
 
data TEST;
  infile 'test.csv' lrecl=2500 firstobs=2 dsd truncover termstr=crlf dlm=',' ;
  input VAR1:$3. VAR2:$11. VAR3:$50. VAR4 VAR5:$2. VAR6:$2. VAR7:$550. VAR8 VAR9:$1. VAR10:$3.;
  VAR7 = translate(VAR7,'_','0D'x);
run;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.TEST" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;VAR1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR3&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;VAR4&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR5&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR6&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR7&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;VAR8&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR9&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;VAR10&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;abc&lt;/TD&gt;
&lt;TD class="l data"&gt;def&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD class="l data"&gt;ghi_jkl&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;TD class="l data"&gt;m&lt;/TD&gt;
&lt;TD class="l data"&gt;n&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;Please supply a simple sample of data like the one above that replicates the issue.&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 00:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378820#M276831</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-25T00:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378844#M276832</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;the original post said that using TERMSTR=CRLF was already tried.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 02:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378844#M276832</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-25T02:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378858#M276833</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Exactly. Just showing that we can't replicate the OP's problem, so something else is at play.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 04:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/378858#M276833</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-25T04:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/621023#M276834</link>
      <description>&lt;P&gt;Building on Tom's excellent solution, I built a macro to take ANY csv and "clean" it - by that I mean:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;* Switch the file to CRLF line endings&lt;/P&gt;
&lt;P&gt;* Switch embedded line breaks (within quotes) to LF&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe this meets the OPs objective of reading it in, and "not changing any data" - as the line breaks are retained (albeit "fixed" to LF format)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To run:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* compile macros */
filename mc url "https://raw.githubusercontent.com/macropeople/macrocore/master/macrocore.sas";
%inc mc;

/* run code */ 
%mp_cleancsv(in=old.csv,out=new.csv)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The &lt;A href="https://github.com/sasjs/core/blob/main/base/mp_cleancsv.sas" target="_self"&gt;source code&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**
  * convert all cr and crlf within quotes to lf
  * convert all other cr or lf to crlf
  */
  data _null_;
    infile &amp;amp;in recfm=n ;
    file &amp;amp;out recfm=n;
    retain isq iscrlf 0 qchar &amp;amp;qchar;
    input inchar $char1. ;
    if inchar=qchar then isq = mod(isq+1,2);
    if isq then do;
      /* inside a quote change cr and crlf to lf */
      if inchar='0D'x then do;
        put '0A'x;
        input inchar $char1.;
        if inchar ne '0A'x then do;
          put inchar $char1.;
          if inchar=qchar then isq = mod(isq+1,2);
        end;
      end;
      else put inchar $char1.;
    end;
    else do;
      /* outside a quote, change cr and lf to crlf */
      if inchar='0D'x then do;
        crblank:
        put '0D0A'x;
        input inchar $char1.;
        if inchar='0D'x then do;
          /* multiple CR indicates CR formatted file with blank lines */
          goto crblank;
        end;
        else if inchar ne '0A'x then do;
          put inchar $char1.;
          if inchar=qchar then isq = mod(isq+1,2);
        end;
      end;
      else if inchar='0A'x then put '0D0A'x;
      else put inchar $char1.;
    end;
  run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 19:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/621023#M276834</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-09-05T19:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/824788#M325759</link>
      <description>The updated link (I can't edit my old post):  &lt;A href="https://core.sasjs.io/mp__cleancsv_8sas.html" target="_blank"&gt;https://core.sasjs.io/mp__cleancsv_8sas.html&lt;/A&gt;</description>
      <pubDate>Thu, 21 Jul 2022 21:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/824788#M325759</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-07-21T21:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/824790#M325761</link>
      <description>&lt;P&gt;Your logic does not handle files with TERMSTR=CR that have empty lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename crlf temp;
data _null_;
  file cr termstr=cr ;
  put 'line 1'///'line 4'/'line 5';
run;

%mp_cleancsv(in=cr,out=crlf);

data _null_;
  infile crlf lrecl=100 recfm=f;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 21:52:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/824790#M325761</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-21T21:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/824800#M325764</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; - much appreciated!  This is exactly why it is so good to share code.  Others can help find the holes in it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I've fixed the bug, also written a test case to cover it, and refreshed the documentation.  The PR is here:  &lt;A href="https://github.com/sasjs/core/pull/290" target="_blank"&gt;https://github.com/sasjs/core/pull/290&lt;/A&gt;</description>
      <pubDate>Thu, 21 Jul 2022 22:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/824800#M325764</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2022-07-21T22:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/911045#M359253</link>
      <description>&lt;P&gt;Hey Tom! Thanks for posting this solution. The second code you provided worked for the line breaks I was facing in my data. To better understand what's going on, could you explain why we add the second input statement and also the put statement at the end (in red)?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;filename fixedcsv temp;
data _null_;
  infile 'sample.csv' lrecl=2500;
  file fixedcsv lrecl=5000 ;
  input ;
  put _infile_ @;
  if countw(_infile_,',','qm') &amp;lt; 10 then do;
    &lt;FONT color="#FF0000"&gt;input ;&lt;/FONT&gt;
    put _infile_ @;
  end;
  &lt;FONT color="#FF0000"&gt;put;&lt;/FONT&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Also I tried replace any single quotes in the data to avoid any complication with "|", however I'm not sure how to change it back to a single quote in the end!&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;filename fixedcsv temp;
data _null_;
  infile 'sample.csv' lrecl=2500;
  file fixedcsv lrecl=5000 ;
  input ;
 &lt;FONT color="#008000"&gt;_infile_=tranwrd(_infile_,"'","|");&lt;/FONT&gt;
  put _infile_ @;
  if countw(_infile_,',','qm') &amp;lt; 10 then do;
    input ;
    put _infile_ @;
  end;
  put;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jan 2024 20:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/911045#M359253</guid>
      <dc:creator>rdum96</dc:creator>
      <dc:date>2024-01-09T20:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Removing embedded carriage returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/911049#M359254</link>
      <description>&lt;P&gt;The second INPUT is to read the next line and write it onto the end of the current line being written.&amp;nbsp; You should probably test whether or not it works when there are multiple extra end-of-lines embedded in the same record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last PUT is the end the line that is being written since the previous PUT statements had trailing&amp;nbsp;@ which does not write the end-of-line characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably the simplest way to convert the |'s back into ' is to do it in the variables you end up with in your SAS dataset after you have successfully read in the fixed file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a data step that will replace all | with ' in all character variables in a SAS dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data apostrophe;
  set bar ;
  array _char_ _character_;
  do over _char_;
    _char_ = translate(_char_,"'",'|');
  end;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jan 2024 22:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-embedded-carriage-returns/m-p/911049#M359254</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-09T22:24:40Z</dc:date>
    </item>
  </channel>
</rss>

