<?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: Split the table counting the row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960890#M374684</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;you could add a parameter to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/61362"&gt;@Stu_SAS&lt;/a&gt;&amp;nbsp;macro XMACRO to execute a macro within the %DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_data(data=, splits=, xmacro=xmacro);
   
   %let dsid  = %sysfunc(open(&amp;amp;data));
   %let n     = %sysfunc(attrn(&amp;amp;dsid, nlobs));
   %let rc    = %sysfunc(close(&amp;amp;dsid));

   %put Total obs: &amp;amp;n;
   %put -------------------------------;

   %do s = 1 %to &amp;amp;splits;
       %let firstobs = %sysevalf(&amp;amp;n-(&amp;amp;n/&amp;amp;splits)*(&amp;amp;splits-&amp;amp;s+1)+1, floor);
       %let obs      = %sysevalf(&amp;amp;n-(&amp;amp;n/&amp;amp;splits)*(&amp;amp;splits-&amp;amp;s), floor);
       %&amp;amp;xmacro;
       %put split:    &amp;amp;s;
       %put firstobs: &amp;amp;firstobs;
       %put obs:      &amp;amp;obs;
       %put total:    %eval(&amp;amp;obs-&amp;amp;firstobs+1);
       %put -------------------------------;
    %end;
%mend;
 

%macro xmacro;
   data cars_split&amp;amp;s(label="&amp;amp;data &amp;amp;firstobs:&amp;amp;obs");
      set &amp;amp;data(firstobs=&amp;amp;firstobs obs=&amp;amp;obs);
      run;
   %mend xmacro;

%split_data(data=sashelp.cars, splits=3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 22:52:34 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2025-03-04T22:52:34Z</dc:date>
    <item>
      <title>Split the table counting the row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960869#M374675</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the sas data with 3 727 000 rows, I would like to split this table on 4 tables, but I dont know how apply the firstobs and lastobs correctly. Could you help me please ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 18:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960869#M374675</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-03-04T18:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Split the table counting the row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960870#M374676</link>
      <description>&lt;P&gt;Splitting a table like you describe is not a good idea, in most situations. So the easiest thing to do is to NOT split it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain why you want to split this table? What can you do with the split table that you can't do without splitting the table?&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 18:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960870#M374676</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-04T18:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Split the table counting the row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960872#M374677</link>
      <description>&lt;P&gt;Hey &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;! I've got some old code that does this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_data(data=, splits=);
   
   %let dsid  = %sysfunc(open(&amp;amp;data));
   %let n     = %sysfunc(attrn(&amp;amp;dsid, nlobs));
   %let rc    = %sysfunc(close(&amp;amp;dsid));

   %put Total obs: &amp;amp;n;
   %put -------------------------------;

   %do s = 1 %to &amp;amp;splits;
       %let firstobs = %sysevalf(&amp;amp;n-(&amp;amp;n/&amp;amp;splits)*(&amp;amp;splits-&amp;amp;s+1)+1, floor);
       %let obs      = %sysevalf(&amp;amp;n-(&amp;amp;n/&amp;amp;splits)*(&amp;amp;splits-&amp;amp;s), floor);
       
       %put split:    &amp;amp;s;
       %put firstobs: &amp;amp;firstobs;
       %put obs:      &amp;amp;obs;
       %put total:    %eval(&amp;amp;obs-&amp;amp;firstobs+1);
       %put -------------------------------;
    %end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%split_data(data=sashelp.cars, splits=3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Total obs: 428
-------------------------------
split:    1
firstobs: 1
obs:      142
total:    142
-------------------------------
split:    2
firstobs: 143
obs:      285
total:    143
-------------------------------
split:    3
firstobs: 286
obs:      428
total:    143
-------------------------------&lt;/PRE&gt;
&lt;P&gt;You can modify this to save each split point to a macro variable. There are probably a dozen other ways to do this, but this is one that I've had for many years to help me find split points. I mostly used it for splitting data up to work in parallel RSUBMIT sessions, but occasionally have used it to send data to people as chunked up CSV files since they requested it that way.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 18:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960872#M374677</guid>
      <dc:creator>Stu_SAS</dc:creator>
      <dc:date>2025-03-04T18:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Split the table counting the row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960882#M374682</link>
      <description>Thank you, Stu_SAS!</description>
      <pubDate>Tue, 04 Mar 2025 20:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960882#M374682</guid>
      <dc:creator>SASdevAnneMarie</dc:creator>
      <dc:date>2025-03-04T20:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Split the table counting the row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960890#M374684</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/286185"&gt;@SASdevAnneMarie&lt;/a&gt;&amp;nbsp;you could add a parameter to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/61362"&gt;@Stu_SAS&lt;/a&gt;&amp;nbsp;macro XMACRO to execute a macro within the %DO;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_data(data=, splits=, xmacro=xmacro);
   
   %let dsid  = %sysfunc(open(&amp;amp;data));
   %let n     = %sysfunc(attrn(&amp;amp;dsid, nlobs));
   %let rc    = %sysfunc(close(&amp;amp;dsid));

   %put Total obs: &amp;amp;n;
   %put -------------------------------;

   %do s = 1 %to &amp;amp;splits;
       %let firstobs = %sysevalf(&amp;amp;n-(&amp;amp;n/&amp;amp;splits)*(&amp;amp;splits-&amp;amp;s+1)+1, floor);
       %let obs      = %sysevalf(&amp;amp;n-(&amp;amp;n/&amp;amp;splits)*(&amp;amp;splits-&amp;amp;s), floor);
       %&amp;amp;xmacro;
       %put split:    &amp;amp;s;
       %put firstobs: &amp;amp;firstobs;
       %put obs:      &amp;amp;obs;
       %put total:    %eval(&amp;amp;obs-&amp;amp;firstobs+1);
       %put -------------------------------;
    %end;
%mend;
 

%macro xmacro;
   data cars_split&amp;amp;s(label="&amp;amp;data &amp;amp;firstobs:&amp;amp;obs");
      set &amp;amp;data(firstobs=&amp;amp;firstobs obs=&amp;amp;obs);
      run;
   %mend xmacro;

%split_data(data=sashelp.cars, splits=3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 22:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Split-the-table-counting-the-row/m-p/960890#M374684</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2025-03-04T22:52:34Z</dc:date>
    </item>
  </channel>
</rss>

