<?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: Replacing all line breaks in CSV export in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783448#M249800</link>
    <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272636"&gt;@ojaro&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	file "&amp;amp;csv_export_file" dsd delimiter='|' lrecl=1000000 MOD encoding="utf-8";
	set mcdtemp.&amp;amp;mc_profile_table(firstobs=&amp;amp;mc_f_obs obs=&amp;amp;mc_csv_i);
	array char _character_;
	do i = 1 to dim(allchar);
		char{i} = compress(char{i},'0d0a'x);
	end;
	put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will remove all occurences of CR and LF in all character variables. Use a translate function instead of compress if you want to insert a blank.&lt;/P&gt;
&lt;P&gt;If you know&amp;nbsp; in which variable&amp;nbsp; the linebreaks occur, then drop the loop and change that variable only.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Dec 2021 19:04:17 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2021-12-01T19:04:17Z</dc:date>
    <item>
      <title>Replacing all line breaks in CSV export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783419#M249786</link>
      <description>&lt;P&gt;Hi, I am using the following code to write large data to CSV:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=mcdtemp.&amp;amp;mc_profile_table(obs=0) out=mcdtemp._names;
  var _all_;
run;

data _null_;
  file "&amp;amp;csv_export_file" dsd delimiter='|' lrecl=1000000 encoding="utf-8";
  set mcdtemp._names end=eof;
  put _name_ @ ;
  if eof then put;
run;

%macro write_profile_csv;
%let mc_csv_i=100000;
%do %while (&amp;amp;mc_csv_i&amp;lt;(&amp;amp;document_count + 100000));
	%let mc_f_obs = %eval(&amp;amp;mc_csv_i. - 99999);
	data _null_;
	  file "&amp;amp;csv_export_file" dsd delimiter='|' lrecl=1000000 MOD encoding="utf-8";
	  set mcdtemp.&amp;amp;mc_profile_table(firstobs=&amp;amp;mc_f_obs obs=&amp;amp;mc_csv_i);
	  put (_all_) (+0);
	run;

	%let mc_csv_i = %eval(&amp;amp;mc_csv_i. + 100000);
%end;
%mend write_profile_csv;
data _null_;
	call execute('%write_profile_csv;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now it appears that the data includes sometimes line breaks that will break the CSVs. &lt;BR /&gt;&lt;BR /&gt;Any suggestions how I could modify the above code in order to compress line breaks from all columns or the only option is to write some code prior that will "clean" the columns?&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Olli&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 17:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783419#M249786</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2021-12-01T17:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing all line breaks in CSV export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783448#M249800</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/272636"&gt;@ojaro&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	file "&amp;amp;csv_export_file" dsd delimiter='|' lrecl=1000000 MOD encoding="utf-8";
	set mcdtemp.&amp;amp;mc_profile_table(firstobs=&amp;amp;mc_f_obs obs=&amp;amp;mc_csv_i);
	array char _character_;
	do i = 1 to dim(allchar);
		char{i} = compress(char{i},'0d0a'x);
	end;
	put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will remove all occurences of CR and LF in all character variables. Use a translate function instead of compress if you want to insert a blank.&lt;/P&gt;
&lt;P&gt;If you know&amp;nbsp; in which variable&amp;nbsp; the linebreaks occur, then drop the loop and change that variable only.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 19:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783448#M249800</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2021-12-01T19:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing all line breaks in CSV export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783459#M249808</link>
      <description>&lt;P&gt;That code looks overly complicated, so solution below ignores the stuff that seems intended just to obfuscate the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to remove CR and/or LF characters from the data you could just loop over the character fields.&amp;nbsp; Here is code to allow you to loop over all the character variables.&amp;nbsp; You can use the older style DO OVER loop with an implicitly referenced array named _CHARACTER_ that uses _N_ as its index variable.&amp;nbsp; &lt;STRONG&gt;That way you do not have to introduce any variable names (for the ARRAY name or the array INDEX) that might conflict with existing variable names.&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file "&amp;amp;csv_export_file" dsd delimiter='|' lrecl=1000000 MOD encoding="utf-8";
  set mcdtemp.&amp;amp;mc_profile_table;
  array _character_ (_n_) _character_;
  do over _character_; _character_ = translate(_character_,'  ','0D0A'x); end;
  put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The only drawback is if you wanted to use the automatic macro variable _n_ for something.&amp;nbsp; Its value is overwritten by being used for indexing into the implicit array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note if the CR and/or LF characters are coming from the formatted values of the variables then you need something more powerful (but slower) such as,&amp;nbsp; &amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/safe_ds2csv.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/safe_ds2csv.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Dec 2021 20:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783459#M249808</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-01T20:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing all line breaks in CSV export</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783571#M249878</link>
      <description>Thank you so much! This works perfectly.</description>
      <pubDate>Thu, 02 Dec 2021 09:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-all-line-breaks-in-CSV-export/m-p/783571#M249878</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2021-12-02T09:24:17Z</dc:date>
    </item>
  </channel>
</rss>

