<?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 split datasets as .txt files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516877#M139638</link>
    <description>&lt;P&gt;No need for macro code or separate SAS dataset to just generate multiple delimited files from a single source dataset.&lt;/P&gt;
&lt;P&gt;Try this little program to split SASHELP.CLASS into files with max of 10 records.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=%sysfunc(pathname(work));

data _null_;
  set sashelp.class ;
  link file;
  put (_all_) (+0);
  return;
file:
  fileno=1+int(_n_/10);
  length filename $300;
  filename = catx('/',"&amp;amp;path",cats('filename_',fileno,'.txt'));
  file out dsd dlm='09'x filevar=filename ;
return;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want a header row on each file then add more logic to test if you are starting a new file and write it.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Nov 2018 21:07:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-28T21:07:47Z</dc:date>
    <item>
      <title>export split datasets as .txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516861#M139634</link>
      <description>&lt;P&gt;dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to split a dataset and export them as .txt file by following codes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split(k=);

data test;
set Sa_step5.Pat_name_with_address_dis end=eof nobs=count;
if eof then call symput('nobs', left(count));
run;

%let n=%sysfunc(int(%eval(&amp;amp;nobs/&amp;amp;k)));

%put &amp;amp;nobs &amp;amp;n;

%do i=1 %to &amp;amp;n;
data Sa_step6.Pat_name_with_address_dis&amp;amp;i test;
set test;
if _N_&amp;lt;=&amp;amp;k then output Sa_step6.Pat_name_with_address_dis&amp;amp;i;
else output test;
run;

PROC EXPORT DATA=Sa_step6.Pat_name_with_address_dis&amp;amp;i
            OUTFILE= "C:\Users\70660\Desktop\Pat_name_with_address_dis\Pat_name_with_address_dis&amp;amp;i.txt" 
            DBMS=tab REPLACE;
			delimiter=',';
RUN;

%end;
%mend;

%split(k=1000);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;however, I create the file like 'Pat_name_with_address_&lt;U&gt;dis1txt&lt;/U&gt;' rather than &lt;SPAN&gt;'Pat_name_with_address_&lt;/SPAN&gt;&lt;U&gt;dis1.txt&lt;/U&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;, could you give me some suggestions about this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 20:32:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516861#M139634</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-11-28T20:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: export split datasets as .txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516871#M139635</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Add another period after the macro variable.&lt;/P&gt;
&lt;P&gt;FYI - its faster to use a data set option to filter your data rather than to create a temporary data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code isn't going to split your data set by the way, it'll create cumulative data. Ie your first data set will have 1000 records, your second will have 2000, your third would have 3000 if the size was 1000 per data set. &lt;STRONG&gt;Is that what you want?&lt;/STRONG&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194466"&gt;@France&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to split a dataset and export them as .txt file by following codes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split(k=);

data test;
set Sa_step5.Pat_name_with_address_dis end=eof nobs=count;
if eof then call symput('nobs', left(count));
run;

%let n=%sysfunc(int(%eval(&amp;amp;nobs/&amp;amp;k)));

%put &amp;amp;nobs &amp;amp;n;

%do i=1 %to &amp;amp;n;
data Sa_step6.Pat_name_with_address_dis&amp;amp;i test;
set test;
if _N_&amp;lt;=&amp;amp;k then output Sa_step6.Pat_name_with_address_dis&amp;amp;i;
else output test;
run;

PROC EXPORT DATA=Sa_step6.Pat_name_with_address_dis&amp;amp;i
            OUTFILE= "C:\Users\70660\Desktop\Pat_name_with_address_dis\Pat_name_with_address_dis&amp;amp;i.txt" 
            DBMS=tab REPLACE;
			delimiter=',';
RUN;

%end;
%mend;

%split(k=1000);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;however, I create the file like 'Pat_name_with_address_&lt;U&gt;dis1txt&lt;/U&gt;' rather than &lt;SPAN&gt;'Pat_name_with_address_&lt;/SPAN&gt;&lt;U&gt;dis1.txt&lt;/U&gt;&lt;SPAN&gt;'&lt;/SPAN&gt;, could you give me some suggestions about this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks in advance&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 20:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516871#M139635</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-11-28T20:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: export split datasets as .txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516872#M139636</link>
      <description>&lt;P&gt;Try Inserting an extra dot '..' after the macro variable as the single dot will be interpreted as the macro variable boundary.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC EXPORT DATA=Sa_step6.Pat_name_with_address_dis&amp;amp;i
            OUTFILE= "C:\Users\70660\Desktop\Pat_name_with_address_dis\Pat_name_with_address_dis&amp;amp;i..txt" 
            DBMS=tab REPLACE;
			delimiter=',';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Nov 2018 20:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516872#M139636</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2018-11-28T20:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: export split datasets as .txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516877#M139638</link>
      <description>&lt;P&gt;No need for macro code or separate SAS dataset to just generate multiple delimited files from a single source dataset.&lt;/P&gt;
&lt;P&gt;Try this little program to split SASHELP.CLASS into files with max of 10 records.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path=%sysfunc(pathname(work));

data _null_;
  set sashelp.class ;
  link file;
  put (_all_) (+0);
  return;
file:
  fileno=1+int(_n_/10);
  length filename $300;
  filename = catx('/',"&amp;amp;path",cats('filename_',fileno,'.txt'));
  file out dsd dlm='09'x filevar=filename ;
return;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want a header row on each file then add more logic to test if you are starting a new file and write it.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Nov 2018 21:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/516877#M139638</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-28T21:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: export split datasets as .txt files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/517850#M140079</link>
      <description>&lt;P&gt;I'd suggest&lt;/P&gt;
&lt;PRE&gt;fileno=1+int(&lt;FONT color="#008000"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt;&lt;/FONT&gt;_n_&lt;FONT color="#008000"&gt;&lt;STRONG&gt;-1)&lt;/STRONG&gt;&lt;/FONT&gt;/10);&lt;/PRE&gt;
&lt;P&gt;to split, e.g., 20 observations into 10+10 rather than 9+10+1.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Dec 2018 11:54:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/export-split-datasets-as-txt-files/m-p/517850#M140079</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-02T11:54:03Z</dc:date>
    </item>
  </channel>
</rss>

