<?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: Export SAS file to text or CSV in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365121#M86688</link>
    <description>This could happen if the dataset used to write the header row is not sorted in the proper VARNUM order.  So if the variables in the actual data set are in the order is A,BMI,HT,B and the list of variable names used to write the header row is in the order A,HT,BMI,B then the header will write 'A,HT,BMI,B' and the variable list A-B will mean 'A BMI HT B'.&lt;BR /&gt;Make sure the dataset use in the last step that writes the file headers and code to write the data lines is sorted by GROUP and VARNUM.&lt;BR /&gt;&lt;BR /&gt;I just did some additional checks of my data and there apprears to be an issue with the CSV files that are being created. Some of the variable names are not being matched up correctly with the data. For example, the data for BMI and weight are reversed so the BMI variable has the weight values and the weight variable has the BMI values.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 07 Jun 2017 18:03:07 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-06-07T18:03:07Z</dc:date>
    <item>
      <title>Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364603#M86486</link>
      <description>&lt;P&gt;I have a large SAS dataset with 201,000 observations and 2800 variables. I need to export it to multiple CSV or text files that have no more than 1000 columns each. The dataset contains two identifiers studyid and partnum that need to be included in each dataset to remerge them later. I have been trying to use proc export with different delimiters but keep getting a couple hundred extra columns. Is there a way to stip a potential delimiter from all the data to make sure I do not get these type of errors? Also, is there a way to export certain groups of variables, maybe alphabetically or something. Any suggestions would be greatly apprecaited.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 14:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364603#M86486</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-06T14:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364606#M86487</link>
      <description>&lt;P&gt;You have several options all somewhat ugly depending on your data set names.&lt;/P&gt;
&lt;P&gt;One would be to use dataset options to list the variables used&lt;/P&gt;
&lt;P&gt;Proc export data=mydataset(keep= idvar1 idvar2 othvar -- anothervar)&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; outfile ="outdata1.csv"&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; dbms=csv&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; replace;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc export data=mydataset(keep= idvar1 idvar2 anothervarplus1 -- someothervar)&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; outfile ="outdata2.csv"&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; dbms=csv&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; replace;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Proc export data=mydataset(keep= idvar1 idvar2&amp;nbsp;someothervarplus1 -- lastvar)&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; outfile ="outdata3.csv"&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; dbms=csv&lt;/P&gt;
&lt;P&gt;&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;&amp;nbsp; replace;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The -- says to keep all of the variables in order so if you have variables:&lt;/P&gt;
&lt;P&gt;var thatvar anothervar somevar yetanothervar&lt;/P&gt;
&lt;P&gt;and use Keep = var -- somevar then the result is to keep the first 4 of the above variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 14:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364606#M86487</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-06T14:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364611#M86488</link>
      <description>&lt;P&gt;The easiest way shoul be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_export(keys=, vars=, outnum=);
&amp;nbsp; &amp;nbsp; &amp;nbsp; proc export data=have(keep=&amp;amp;keys &amp;amp;vars);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; outfile "..path..name&amp;amp;outnum..csv"   /* adapt path and file name prefix */
&amp;nbsp; &amp;nbsp; &amp;nbsp;run;
%mend split_export;
%split_export(keys=studid partnum, vars=var1-var998 , 1);
%split_export(keys=studid partnum, vars=var999-var1996 ,2);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Of course, if your variable names have no constant prefix (like var...) you shall need more comlicated code,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but it is possible.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364611#M86488</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-06T15:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364613#M86489</link>
      <description>&lt;P&gt;Thank you both for the proposed solutions. I will try both now. My variable names do not have a constant prefix so I will try to modify to accomodate this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For my delimiter issue, is there something I should do that would help with this or is it a non-issue?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364613#M86489</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-06T15:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364615#M86491</link>
      <description>&lt;P&gt;If you choose dbms=csv the the deimiter is a comma,&lt;/P&gt;
&lt;P&gt;otherwise try define dlm= &amp;nbsp;your own delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there is no text field that may contain commas then prefer the dbms=csv;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364615#M86491</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-06T15:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364616#M86492</link>
      <description>&lt;P&gt;Thank you. Part of my problem is that there are text fields that contain commas and many other characters so it is difficult to know what delimiter might work best. Is there a stip a certain character from the entire dataset to make sure I can export correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364616#M86492</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-06T15:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364617#M86493</link>
      <description>&lt;P&gt;Usually text variables don't include tabs.&lt;/P&gt;
&lt;P&gt;try dbms=tab or dlm='09'x;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364617#M86493</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-06T15:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364620#M86494</link>
      <description>&lt;P&gt;1) CSV (or any delimited file) is easy to write with a data step. No need to get complex and try to use proc's to generate them.&lt;/P&gt;
&lt;P&gt;2) SAS will put quotes around values that contain delimiters so there is no need to eliminate them from your data. You should check the tool that you are using to read the files and make sure that it understands this basic rule of delimited files.&lt;/P&gt;
&lt;P&gt;3) You can use PROC CONTENTS or other methods to get a list of the variables in your file and then break them into sets of less than 1,000 variables. Then use those sets to generate the data steps to write your CSV files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=contents(keep=varnum name) noprint ; run;
proc sort data=contents;
  where lowcase(name) not in ('studyid','partnum');
  by varnum;
run;
data files ;
  group+1;
  do col=3 to 1000 until (eof);
    set contents end=eof;
    output;
  end;
run;
filename code temp;
data _null_;
 file code lrecl=80 ;
 do until (last.group);
   set files ;
   by group ;
   fname = cats('outfile',group,'.csv');
   if first.group then put
    / 'data _null_;'
    / '  set have; '
    / '  file ' fname :$quote. 'dsd lrecl=100000;'
    / '  if _n_=1 then do;'
    / '    put "studyid" @;'
    / '    put "partnum" @;'
   ;
   put '    put ' name :$quote. '@;' ;
   if last.group then put
      '    put;'
    / '  end;'
   ;
 end;
 do until (last.group);
   set files ;
   by group ;
   if first.group then put
    / '  put ( studyid partnum ' @
   ;
   put name @ ;
   if last.group then put
      ') (+0);'
    / 'run;'
   ;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then just use %INCLUDE to run the generated code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code / source2 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364620#M86494</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-06T15:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364626#M86497</link>
      <description>&lt;P&gt;Why do you need to eliminate the delimiters from the data? SAS will automatically include quotes around values that contain delimiters. &amp;nbsp;What software are you using to read the files that does not understand that?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364626#M86497</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-06T15:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364627#M86498</link>
      <description>&lt;P&gt;I don't need to eliminate delimiters, I was just running into an issue of extra rows being created in the past so was trying to come up with a solution to fix this. I am trying a couple different options now that you all have suggested. Thank you for your promopt responses and help!&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 15:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364627#M86498</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-06T15:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364633#M86502</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297"&gt;@rfarmenta&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I don't need to eliminate delimiters, I was just running into an issue of extra rows being created in the past so was trying to come up with a solution to fix this. I am trying a couple different options now that you all have suggested. Thank you for your promopt responses and help!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Extra rows" likely because of carriage return or line feed characters in a data field. Proc export will only create one row of output per observation &lt;STRONG&gt;but&lt;/STRONG&gt; if the data contains something that another application considers and end of row the result will look like that. If you have one or more data fields that are some sort of unstructed comment or note field you may consider investigating if the variable has such characters as part of the content and remove them prior to export.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 16:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364633#M86502</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-06T16:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364654#M86505</link>
      <description>&lt;P&gt;Thank you! I tried that code that Tom sent and when I open the data in excel all of the variable names are in the first cell so when I read that data set into SAS is names all the variables var1-var1000. I am not sure what is going on with that. Also, is there a way to have sepcial missing values just be exported as missing since most other programs do not recognize special missing?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 17:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364654#M86505</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-06T17:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364666#M86509</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/297"&gt;@rfarmenta&lt;/a&gt;&amp;nbsp;wrote: "&lt;SPAN&gt;when I open the data in excel all of the variable names are in the first cell so when I read that data set into SAS is names all the variables var1-var1000. I am not sure what is going on with that."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It is not clear what have you run and what results you got. Please post log of your run and screenshot of the excel.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As to missing values, you can try add next statement before the proc export or the data steps:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Jun 2017 17:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364666#M86509</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-06-06T17:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364670#M86511</link>
      <description>&lt;P&gt;Here is corrected code that will generate the delimiters for the header row manually in the code. &amp;nbsp;The code I tried before with the trailing&amp;nbsp;@ would only work when putting a variable and not a string literal. &amp;nbsp;You could adapt the code to use teh variable list from the list used to generate the code, but then the generated code could not be used later as a stand alone program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
 file code lrecl=80 ;
 do until (last.group);
   set files ;
   by group ;
   fname = cats('outfile',group,'.csv');
   if first.group then put
    / 'data _null_;'
    / '  set have; '
    / '  file ' fname :$quote. 'dsd lrecl=100000;'
    / '  if _n_=1 then put "studyid,partnum," ' @
   ;
   put  name :$quote. @ ;
   if last.group then put / '  ;' ;
   else put '"," ' @ ;
 end;
 do until (last.group);
   set files ;
   by group ;
   if first.group then put
      '  put ( studyid partno ' @
   ;
   put name @ ;
   if last.group then put
      ') (+0);'
    / 'run;'
   ;
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want special missing value to print as missing instead of the letter attached to them then you might need to add more code into the generated program to set the special missing to normal missing. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this would work even if the source data did not have any numeric variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; array __N _n_ _numeric_;
 do _n_=1 to dim(__N); if missing(__N(_n_)) then __N(_n_)=.; end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Similarly if you want to trap CR and/or LF in the character variables you could add code like this to convert them into spaces. The first two lines purposely adds the variable _C_ to insure that the _CHARACTER_ variable list is not empty. &amp;nbsp;You might not need those two lines if your STUDYID variable is also character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; retain _c_ ' ' ;
 drop _c_;
 array __C _character_;
 do _n_=1 to dim(__C); __C(_n_) = translate(__C(_n_),'  ','0D0A'x); end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 18:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364670#M86511</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-06T18:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364686#M86515</link>
      <description>&lt;P&gt;Thank you, Tom! This worked wonderfully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One other thing, is&amp;nbsp; there a way to get rid of all of the tabs in the data? Apparently the group this is being shared with needs the tabs to be removed for their ingestion of the data.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 19:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364686#M86515</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-06T19:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364767#M86541</link>
      <description>&lt;P&gt;If you use the code that I posted to loop over all characters variables and translate CR or LF to spaces you can easily adjust it to also translate the tabs into spaces. Just add one more character to both the TO and FROM arguments to the TRANSLATE() function. The hex code for a tab is '09'x.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 21:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364767#M86541</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-06T21:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364786#M86549</link>
      <description>&lt;P&gt;Here is a simplied version of what I posted before that will write all of the files in one data step. &amp;nbsp;That makes both the code generation easier and the execution faster.&lt;/P&gt;
&lt;P&gt;First get the contents and divide into groups. &amp;nbsp;Note that with this verison the sort by VARNUM is critical since postional variable lists (A -- B) will be used later to write the columns. You can change the upper bound of 1000 in the DO loop to control how many variables are written to each file. The lower bound of three is to allow room for the two id variables at the front.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=contents(keep=varnum name) noprint ; run;
proc sort data=contents;
  where lowcase(name) not in ('studyid','partnum');
  by varnum;
run;
data files ;
  group+1;
  do col=3 to 1000 ;
    set contents;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now use this file to both write the header lines to each of the output files and also write the code needed to write the data lines. Modify the statement that creates the FNAME variable to match your file naming requirement. Note the inclusion of the MOD option in the generated FILE statements. That is because the header line will already be written be this step and the step that writes the data just needs to append to the existing files. Also note it is using a line length of 1,000,000 which should be more than enough for 1,000 variables as long as they aren't all extremely long character variables. &amp;nbsp;SAS can support longer line lengths, but it might depend on your operating system.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
   set files ;
   by group ;
   fname = cats('outfile',group,'.csv');
   file csv filevar=fname dsd lrecl=1000000 ;
   if first.group then put 'studyid,partnum,' @;
   put name @ ;
   if last.group then put ;
   file code ;
   if first.group then put
    / 'file ' fname :$quote. 'dsd mod lrecl=1000000;'
    / 'put ( studyid partnum ' name '-- ' @
   ;
   if last.group then put name ') (+0);' ;
run&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now write the data lines. Notice that the included code only had the FILE and PUT statements so the rest of the data step is just plain code that should be easier to edit. &amp;nbsp;I included loops to handle both the special missing value issue and blanking out tabs, cr and lf characters. I used two SET statements to force STUDYID and PARTNUM to the beginning of the data vector so that the postional variable lists will not include them. &amp;nbsp;I used the INDSNAME= option on the second SET just to make sure there was at least one character variable defined for the _character_ variable list used in the array definition. I also used the DO OVER style loops that SAS is trying to remove from the documentation. It is just so much easier to not have to code indexes for operations that you want to apply to all members of an array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have (keep=studyid partnum);
  set have (drop=studyid partnum) indsname=__C__;
  array __C _character_;
  array __N _n_ _numeric_;
  do over __C ; __C=translate(__C,'   ','090A0D'x); end;
  do over __N ; if missing(__N) then __N=.; end;
  %include code / source2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 23:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/364786#M86549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-06T23:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365094#M86674</link>
      <description>&lt;P&gt;Thank you, Tom! This new code is definitely more efficent. This is exactly what I needed and I appreciate your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One last question, I am being asked to remove commas that may exist in character values as well. Can I just use this modified version of what you wrote:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do over __C ; __C=translate(__C,'&amp;nbsp;&amp;nbsp; ','002C'x); end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure that is the right HEX code for commas though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you again!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 17:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365094#M86674</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-07T17:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365100#M86676</link>
      <description>'2C'x is the right code for a comma.  But you could also use '00'x||',' as to specify the two character string of a binary zero and a comma.&lt;BR /&gt;&lt;BR /&gt;Thank you, Tom! This new code is definitely more efficent. This is exactly what I needed and I appreciate your help.&lt;BR /&gt;&lt;BR /&gt;One last question, I am being asked to remove commas that may exist in character values as well. Can I just use this modified version of what you wrote:&lt;BR /&gt;&lt;BR /&gt;do over __C ; __C=translate(__C,'   ','002C'x); end;&lt;BR /&gt;&lt;BR /&gt;I am not sure that is the right HEX code for commas though.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Jun 2017 17:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365100#M86676</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-06-07T17:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Export SAS file to text or CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365117#M86685</link>
      <description>&lt;P&gt;I just did some additional checks of my data and there apprears to be an issue with the CSV files that are being created. Some of the variable names are not being matched up correctly with the data. For example, the data for BMI and weight are reversed so the BMI variable has the weight values and the weight variable has the BMI values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know what might be going on to make this happen?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 17:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-SAS-file-to-text-or-CSV/m-p/365117#M86685</guid>
      <dc:creator>rfarmenta</dc:creator>
      <dc:date>2017-06-07T17:50:43Z</dc:date>
    </item>
  </channel>
</rss>

