<?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 SAS Export dataset as csv or excel preserving line break in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/490906#M128600</link>
    <description>&lt;P&gt;I am trying to export my dataset from SAS to excel either is csv or xls format however, when I do this the columns with line breaks messes up my excel. Is there a way to export SAS dataset to excel preserving line breaks? I also need to display labels instead of column names and the dataset is fairly large approx. 150,000 rows.&lt;/P&gt;&lt;P&gt;Here is what I did,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc export data=Final_w_label
outfile='work/ExtractExcel.csv'
dbms=csv label replace;
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Aug 2018 16:22:01 GMT</pubDate>
    <dc:creator>priv</dc:creator>
    <dc:date>2018-08-29T16:22:01Z</dc:date>
    <item>
      <title>SAS Export dataset as csv or excel preserving line break</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/490906#M128600</link>
      <description>&lt;P&gt;I am trying to export my dataset from SAS to excel either is csv or xls format however, when I do this the columns with line breaks messes up my excel. Is there a way to export SAS dataset to excel preserving line breaks? I also need to display labels instead of column names and the dataset is fairly large approx. 150,000 rows.&lt;/P&gt;&lt;P&gt;Here is what I did,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;proc export data=Final_w_label
outfile='work/ExtractExcel.csv'
dbms=csv label replace;
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 16:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/490906#M128600</guid>
      <dc:creator>priv</dc:creator>
      <dc:date>2018-08-29T16:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Export dataset as csv or excel preserving line break</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/491474#M128897</link>
      <description>&lt;P&gt;If you quote the variables with a break, Excel will recognise them:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file "\\&amp;amp;path\test.csv";
  put 'a,b';
  put 'aa,bbbb';
  put 'aa,"bb' '0a'x 'bb"';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2018 23:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/491474#M128897</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-30T23:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Export dataset as csv or excel preserving line break</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/491481#M128901</link>
      <description>&lt;P&gt;Excel can recognize embedded line breaks as long as the value is quoted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write the CSV file yourself instead of depending on a proc.&amp;nbsp; It will be faster anyway.&amp;nbsp; Then if you know which columns MIGHT include the line break you can force SAS to write the value as quoted by using the ~ modifier on the PUT statement.&lt;/P&gt;
&lt;P&gt;Let's do a little test using SASHELP.CARS as our example.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set sashelp.cars (obs=5 keep=
    make                             /* $13.   */
    model                            /* $40.   */
    weight                           /* best12. Weight (LBS) */
    wheelbase                        /* best12. Wheelbase (IN) */
    length                           /* best12. Length (IN) */
);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So assuming that MODEL is the variable that might contain line breaks our output program might look like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
proc export data=test(obs=0) outfile=csv dbms=csv label ; run;

data _null_;
  set test;
  file csv dsd mod ;
  put make model ~ weight wheelbase length ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the result:&lt;/P&gt;
&lt;PRE&gt;482  data _null_;
483   infile csv ;
484   input;
485   list;
486  run;

NOTE: The infile CSV is:
      Filename=...

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9
1         "Make","Model","Weight (LBS)","Wheelbase (IN)","Length (IN)" 60
2         Acura,"MDX",4451,106,189 24
3         Acura,"RSX Type S 2dr",2778,101,172 35
4         Acura,"TSX 4dr",3230,105,183 28
5         Acura,"TL 4dr",3575,108,186 27
6         Acura,"3.5 RL 4dr",3880,115,197 31
NOTE: 6 records were read from the infile CSV.
      The minimum record length was 24.
      The maximum record length was 60.&lt;/PRE&gt;
&lt;P&gt;If you don't mind generating a lot of extra quotes you could just add the ~ modifier to every variable. Then you don't need to know the variable is the last step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set test;
  file csv dsd mod ;
  put (_all_) (~);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Aug 2018 01:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Export-dataset-as-csv-or-excel-preserving-line-break/m-p/491481#M128901</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-31T01:35:05Z</dc:date>
    </item>
  </channel>
</rss>

