<?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: Create separate CSVs for each record in a SAS dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606730#M176233</link>
    <description>&lt;P&gt;the rules are as follows:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first csv will be named as output1.csv&lt;BR /&gt;the second csv will be named as output2.csv&lt;/P&gt;&lt;P&gt;2)&lt;/P&gt;&lt;P&gt;output csvs does not require headers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note:&lt;/P&gt;&lt;P&gt;there is a column in the source dataset that is rownumber...&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Nov 2019 23:14:37 GMT</pubDate>
    <dc:creator>Suminder</dc:creator>
    <dc:date>2019-11-23T23:14:37Z</dc:date>
    <item>
      <title>Create separate CSVs for each record in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606716#M176227</link>
      <description>&lt;P&gt;Hi Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have following sas dataset&lt;/P&gt;&lt;P&gt;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; Age &amp;nbsp; &amp;nbsp; &amp;nbsp; Country&lt;/P&gt;&lt;P&gt;Sam &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 15 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; CA&lt;/P&gt;&lt;P&gt;Rohan &amp;nbsp; &amp;nbsp;&amp;nbsp; 13 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA&lt;/P&gt;&lt;P&gt;Mich &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; IND&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the result required is separate CSVs for each record in above dataset. In this case it will be three CSVs with one record each.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2019 21:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606716#M176227</guid>
      <dc:creator>Suminder</dc:creator>
      <dc:date>2019-11-23T21:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate CSVs for each record in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606718#M176228</link>
      <description>&lt;P&gt;Use the filevar= option in the file statement.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2019 22:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606718#M176228</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-23T22:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate CSVs for each record in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606723#M176229</link>
      <description>&lt;P&gt;Do you need to control the names?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not ODS CSVALL is a good option.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

ods csvall body = '/home/userName/Demo1/demo.csv' newfile=bygroup;

options nobyline;

proc print data=have noobs;
by name;
var name age country;
run;

ods csvall close;
options byline;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Nov 2019 22:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606723#M176229</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-23T22:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate CSVs for each record in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606725#M176230</link>
      <description>&lt;P&gt;And another example if you want to use a FILEVAR approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/047bc83a85672f4dd546" target="_blank"&gt;https://gist.github.com/statgeek/047bc83a85672f4dd546&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the folders/myfolders section and you can run the code and test it yourself and then adapt it for your data needs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two other things to think about:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Filename changing for each record, what are the rules&lt;/LI&gt;
&lt;LI&gt;Does each file need a header record&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SORT DATA=SASHELP.CARS OUT=CARS;
BY make;
RUN;


DATA _NULL_;

SET cars; *Dataset to be exported;
BY make; *Variable that file is to be split on;

*Create path to file that is to be exported;
if first.make then out_file=cats(&lt;FONT size="4" color="#FF6600"&gt;&lt;STRONG&gt;'/folders/myfolders/'&lt;/STRONG&gt;&lt;/FONT&gt;, trim(make));

file temp filevar=out_file dlm=',' dsd;

*If first value of make then output column names;
if first.make then 
put 'Make, Model, MPG_HIGHWAY, MPG_CITY';

*Output variables;
put make model mpg_highway mpg_city;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Nov 2019 22:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606725#M176230</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-11-23T22:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate CSVs for each record in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606730#M176233</link>
      <description>&lt;P&gt;the rules are as follows:&lt;/P&gt;&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first csv will be named as output1.csv&lt;BR /&gt;the second csv will be named as output2.csv&lt;/P&gt;&lt;P&gt;2)&lt;/P&gt;&lt;P&gt;output csvs does not require headers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note:&lt;/P&gt;&lt;P&gt;there is a column in the source dataset that is rownumber...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Nov 2019 23:14:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606730#M176233</guid>
      <dc:creator>Suminder</dc:creator>
      <dc:date>2019-11-23T23:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create separate CSVs for each record in a SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606823#M176283</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281130"&gt;@Suminder&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;the rules are as follows:&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the first csv will be named as output1.csv&lt;BR /&gt;the second csv will be named as output2.csv&lt;/P&gt;
&lt;P&gt;2)&lt;/P&gt;
&lt;P&gt;output csvs does not require headers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;note:&lt;/P&gt;
&lt;P&gt;there is a column in the source dataset that is rownumber...&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Build the filename as a variable in the data step that is writing the files.&amp;nbsp; You can then use the FILEVAR= option on the FILE statement to have SAS make many different files.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set have ;
  length fname $200 ;
  fname = cats('output',rownumber,'.csv');
  file dummy filevar=fname dsd ;
  put Name Age Country ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Remember to add the directory to the FNAME value or else output1.csv etc will be created in the current working directory of process that is running SAS.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Nov 2019 15:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-separate-CSVs-for-each-record-in-a-SAS-dataset/m-p/606823#M176283</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-24T15:58:55Z</dc:date>
    </item>
  </channel>
</rss>

