<?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: how to: export a sas dataset into multiple csv files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831719#M328711</link>
    <description>&lt;P&gt;You can do this in a single data step by using the FILEVAR= option of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n15o12lpyoe4gfn1y1vcp6xs6966.htm" target="_self"&gt;FILE Statement&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Change the filename every time mod(_n_,4) is 1.&lt;/P&gt;</description>
    <pubDate>Sun, 04 Sep 2022 15:15:45 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-09-04T15:15:45Z</dc:date>
    <item>
      <title>how to: export a sas dataset into multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831717#M328710</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have sas file with 200 rows. I need to split them into 4 rows per csv file.&amp;nbsp; So I created&amp;nbsp; variable A and numbered each row sequential from 1 to 200.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then programmed the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ods csv file="export.csv";&lt;BR /&gt;proc print data=test (where=(A between 1 and 4)) noobs;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I now have to change the "1" and "4" manually until I get to "197" and "200".&amp;nbsp; Is there a way to automate this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for time&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 15:05:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831717#M328710</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2022-09-04T15:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to: export a sas dataset into multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831719#M328711</link>
      <description>&lt;P&gt;You can do this in a single data step by using the FILEVAR= option of the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n15o12lpyoe4gfn1y1vcp6xs6966.htm" target="_self"&gt;FILE Statement&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Change the filename every time mod(_n_,4) is 1.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 15:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831719#M328711</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-09-04T15:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to: export a sas dataset into multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831723#M328712</link>
      <description>&lt;P&gt;You can write CSV files using a simple data step, no need for either ODS or PROC EXPORT.&lt;/P&gt;
&lt;P&gt;You even use the CALL VNEXT() function to let you write the header row to each file.&lt;/P&gt;
&lt;P&gt;So here is an example using SASHELP.CLASS as the example dataset and the current WORK directory as the destination for writing the files that creates a series of files named export1.csv, export2.csv etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=%sysfunc(pathname(work));
data _null_;
  do _n_=1 to 4 ;
    set sashelp.class;
    if _n_=1 then link names;
    put (_all_)(+0);
  end;
return;
names:
  length __name_ $32 __fileno 8 __filename $256;
  __fileno+1;
  __filename = cats("&amp;amp;path/export",__fileno,'.csv');
  file csv dsd filevar=__filename;
  do while(1);
    call vnext(__name_);
    if lowcase(__name_) = '__name_' then leave;
    put __name_ @;
  end;
  put; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So for your problem just change the setting of the macro variable PATH to the place you want to create the file.&amp;nbsp; Change the SET statement to reference the dataset you want to write.&amp;nbsp; Can change the line that is building the unique filename to reflect how you want the filenames created.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 16:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831723#M328712</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-04T16:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to: export a sas dataset into multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831726#M328713</link>
      <description>awesome, thank you so much!</description>
      <pubDate>Sun, 04 Sep 2022 18:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831726#M328713</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2022-09-04T18:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to: export a sas dataset into multiple csv files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831799#M328759</link>
      <description>&lt;PRE&gt;%let n=4;

data have;
 set sashelp.class end=last;
 if mod(_n_,&amp;amp;n.)=1 then _id_+1;
 if last then call symputx('_id_',_id_);
run;

%macro export_csv(dsn=,path=);
%do i=1 %to &amp;amp;_id_.;
data temp(drop=_id_);
 set &amp;amp;dsn.(where=(_id_=&amp;amp;i.));
run;
proc export data=temp outfile="&amp;amp;path.\export_&amp;amp;i..csv" dbms=csv replace;
run;
%end;
%mend;
%export_csv(dsn=have,path=c:\temp)&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Sep 2022 11:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-export-a-sas-dataset-into-multiple-csv-files/m-p/831799#M328759</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-05T11:43:18Z</dc:date>
    </item>
  </channel>
</rss>

