<?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: Exporting large number of variables to CSV in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367237#M275332</link>
    <description>&lt;P&gt;There's a problem with proc export and lots of variables, as the put statement for the header exceeds the maximum length of a SAS statement (32767).&lt;/P&gt;
&lt;P&gt;Create a dataset of variable names from dictionary.columns (or sashelp.vcolumn), and use call execute in a data _null_ step off that dataset to create your export data step dynamically.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2017 06:57:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-06-15T06:57:08Z</dc:date>
    <item>
      <title>Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367201#M275330</link>
      <description>&lt;P&gt;I am trying to export a sas dataset to a CSV file. The dataset has 4,048 variables and 57,868 records. All the variables are exported correctly, but for some reason, the header gets truncated. Only the first 3,366 names are exported to the first records. Any idea why? This is how the header looks Var4570Post,,,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A few commas were added to the end, not sure why, but I should have another 682 variables in the header record.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue?? Is there a limit of variables to export? Should I try another method instead of proc export? Suggestions? Thanks in advance!!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 01:08:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367201#M275330</guid>
      <dc:creator>mjsorrondegui</dc:creator>
      <dc:date>2017-06-15T01:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367209#M275331</link>
      <description>&lt;P&gt;It's using the default LRECL which is cutting off. Try a manual export instead:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Proc-Export-for-large-files/td-p/188894" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Proc-Export-for-large-files/td-p/188894&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure if ODS CSV would be helpful here.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 02:32:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367209#M275331</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-15T02:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367237#M275332</link>
      <description>&lt;P&gt;There's a problem with proc export and lots of variables, as the put statement for the header exceeds the maximum length of a SAS statement (32767).&lt;/P&gt;
&lt;P&gt;Create a dataset of variable names from dictionary.columns (or sashelp.vcolumn), and use call execute in a data _null_ step off that dataset to create your export data step dynamically.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 06:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367237#M275332</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-15T06:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367270#M275333</link>
      <description>&lt;P&gt;Another thought, could you not re-structure your data? &amp;nbsp;It sounds like you have a normalised dataset - i.e. data goes across (as 57k records is not much but 4k variables is). &amp;nbsp;If I took this data:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; WEEK1 &amp;nbsp; &amp;nbsp;WEEK2 &amp;nbsp; &amp;nbsp;WEEK3...&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 34 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;56&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And re-structured it to:&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; WEEK_NO &amp;nbsp; RESULT&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;34&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;56&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data is effectively the same, however th import/export and programming work with this data is far simpler. &amp;nbsp; Then if I need a transposed dataset for output a simple proc transpose can achieve this.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 08:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367270#M275333</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-15T08:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367313#M275334</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148989"&gt;@mjsorrondegui&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;As others already pointed out there is a limitation how many characters of header Proc Export can write.&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;already hinted using ODS could be an alternative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code worked for me:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  firstVar='AAAA';
  array allMyVars_0123456789012345_ {4048} 3. (4048*1);
/*  do i=1 to 57868;*/
  do i=1 to 100;
    output;
  end;
  stop;
run;


ods _all_ close;
ods tagsets.csv  file='c:\temp\test.csv';
proc print data=have noobs; 
run;
ods csv close;
ods listing;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2017 10:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367313#M275334</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-15T10:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367416#M275335</link>
      <description>&lt;P&gt;While the ODS method works, the following data step method worked as well AND ran about 500 times faster:&lt;/P&gt;
&lt;PRE&gt;%let flname=have;
%let outfname=/folders/myfolders/testit3.csv;

proc transpose data=sashelp.vcolumn (where=(libname eq upcase("WORK") and
                                     memname eq upcase("&amp;amp;flname.")))
               out=vcolumnt (drop=_NAME_ _LABEL_);
  var name;
run;

data _null_;
  file "&amp;amp;outfname." dlm=',' dsd lrecl=2000000;
  set vcolumnt;
  put (_all_) (+0);
run;

data _null_;
  file "&amp;amp;outfname." dlm=',' dsd lrecl=2000000 mod;
  set &amp;amp;flname.;
  /* format _all_; */
  put (_all_) (+0);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 15:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367416#M275335</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-06-15T15:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting large number of variables to CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367539#M275336</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The advantage of using ODS is that it also does the quoting of character variables inclusive treatment of embedded quotes in a string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option would be utility macro %ds2csv()&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lebaseutilref/64791/HTML/default/viewer.htm#n0yo3bszlrh0byn1j4fxh4ndei8u.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lebaseutilref/64791/HTML/default/viewer.htm#n0yo3bszlrh0byn1j4fxh4ndei8u.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2017 22:56:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exporting-large-number-of-variables-to-CSV/m-p/367539#M275336</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-15T22:56:35Z</dc:date>
    </item>
  </channel>
</rss>

