<?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: Splitting a data set into many different files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717911#M222089</link>
    <description>&lt;P&gt;Splitting data sets into many different files is generally a sub-optimal thing to do, and requires more programming to get the desired results. Why do you need separate data sets? What does that allow you to do compared to keeping everything in one data set?&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2021 14:30:00 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-02-09T14:30:00Z</dc:date>
    <item>
      <title>Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717910#M222088</link>
      <description>&lt;P&gt;Dear All:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;I have a large file and want to split it into several smaller files using the Variable ID.&amp;nbsp; The ID's are in numerical format and there are at least 100 of them.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also want to split these files by ID to the CSV format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp; Randy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 14:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717910#M222088</guid>
      <dc:creator>RandyStan</dc:creator>
      <dc:date>2021-02-09T14:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717911#M222089</link>
      <description>&lt;P&gt;Splitting data sets into many different files is generally a sub-optimal thing to do, and requires more programming to get the desired results. Why do you need separate data sets? What does that allow you to do compared to keeping everything in one data set?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 14:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717911#M222089</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-09T14:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717912#M222090</link>
      <description>&lt;P&gt;It is simple to write to CSV file using a data step.&amp;nbsp; You can use the FILENAME= option on the FILE statement dynamically write to a different file based on the ID value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set mydata ;
  length filename $200 ;
  filename = cats('/somepath/basename_',id,'.csv');
  file csv dsd filename=filename ;
  put var1 var2 .... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to include a header row then you will need to process the dataset BY ID and include an additional put to write the header row.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set mydata ;
  by id;
  length filename $200 ;
  filename = cats('/somepath/basename_',id,'.csv');
  file csv dsd filename=filename ;
  if first.id then put 'var1,var2,....';
  put var1 var2 .... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 14:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717912#M222090</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-09T14:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717917#M222093</link>
      <description>&lt;P&gt;You do not need to split the dataset before you create the separate CSV's:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by id;
run;

data _null_;
set have;
by id;
length fname $254;
fname = cats("/path/",id,".csv");
file dummy filevar=fname dlm="," dsd;
if first.id then put "ID,othervar";
put
  id
  othervar
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Feb 2021 14:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717917#M222093</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-09T14:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717958#M222107</link>
      <description>&lt;P&gt;Dear All&lt;/P&gt;&lt;P&gt;&amp;nbsp; Just to clarify I want to split the data into files both in SAS and CSV format&lt;/P&gt;&lt;P&gt;&amp;nbsp; Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 17:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717958#M222107</guid>
      <dc:creator>RandyStan</dc:creator>
      <dc:date>2021-02-09T17:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717969#M222112</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133090"&gt;@RandyStan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear All&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Just to clarify I want to split the data into files both in SAS and CSV format&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is the justification for creating separate SAS datasets for each value of ID?&amp;nbsp; In general it is not worth the effort as it so easy to just add a WHERE statement to limit any work you are doing to the ID of interest.&amp;nbsp; (Plus when the data is all together you can do analysis on multiple ID values at once.)&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 18:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/717969#M222112</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-09T18:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/718216#M222231</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
run;


proc freq data=have noprint;
table age/out=age nopercent;
run;
data _null_;
 set age;
 call execute(catt('data _',age,';set have;if age=',age,';run;
proc export data=_',age,' outfile="c:\temp\',age,'.csv" dbms=csv replace;run;'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/718216#M222231</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-10T12:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a data set into many different files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/718229#M222235</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133090"&gt;@RandyStan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear All&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Just to clarify I want to split the data into files both in SAS and CSV format&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What for? You can always use BY processing to do analysis at once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have done a split along a variable only once, when processing a whole dataset at once would run out of disk space. In 20+ years of SAS work and in one of 1000+ batch programs.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 13:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-data-set-into-many-different-files/m-p/718229#M222235</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-10T13:16:13Z</dc:date>
    </item>
  </channel>
</rss>

