<?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 dataset by a variables value and exporting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/861745#M340380</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;General approach: by group processing&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
   by site;
run;

ods excel file="yourpathandfilenamegohere.xlsx"
       options(sheet_interval="BYGROUP");
proc print data=have noobs;
   by site;
ods excel close;&lt;/PRE&gt;
&lt;P&gt;The option Sheet_interval="Bygroup" will create a separate sheet for each level of the BY variable in the Proc Print output.&lt;/P&gt;
&lt;P&gt;Note: if you have multiple procedures trying to send related output for a By variable this doesn't work as the different procedures are processing data at different points of the output to ODS cycle.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Mar 2023 15:17:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-03-01T15:17:46Z</dc:date>
    <item>
      <title>Splitting dataset by a variables value and exporting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/861740#M340378</link>
      <description>&lt;P&gt;Hello, I'm looking to divide a dataset by the value of the &lt;EM&gt;site&lt;/EM&gt; variable in my dataset and export the data tables to separate tabs in excel.&amp;nbsp; I would like this to be done dynamically because I have about 14 values for the &lt;EM&gt;site&lt;/EM&gt; variable.&amp;nbsp; The data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Site&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&lt;/P&gt;&lt;P&gt;site 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN23&lt;/P&gt;&lt;P&gt;site 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN23&lt;/P&gt;&lt;P&gt;site 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;150&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The outcome would be :&lt;/P&gt;&lt;P&gt;table 1&lt;/P&gt;&lt;P&gt;Site&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&lt;/P&gt;&lt;P&gt;site 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 2&lt;/P&gt;&lt;P&gt;Site&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&lt;/P&gt;&lt;P&gt;site 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 3&lt;/P&gt;&lt;P&gt;Site&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&lt;/P&gt;&lt;P&gt;site 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;150&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01JAN23&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 14:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/861740#M340378</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-03-01T14:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dataset by a variables value and exporting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/861745#M340380</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;General approach: by group processing&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
   by site;
run;

ods excel file="yourpathandfilenamegohere.xlsx"
       options(sheet_interval="BYGROUP");
proc print data=have noobs;
   by site;
ods excel close;&lt;/PRE&gt;
&lt;P&gt;The option Sheet_interval="Bygroup" will create a separate sheet for each level of the BY variable in the Proc Print output.&lt;/P&gt;
&lt;P&gt;Note: if you have multiple procedures trying to send related output for a By variable this doesn't work as the different procedures are processing data at different points of the output to ODS cycle.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 15:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/861745#M340380</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-01T15:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dataset by a variables value and exporting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/865962#M341980</link>
      <description>Hello, I have to sort the data by certain variables, like date as well before it is exported to excel. Is there a way I can do this with this code?</description>
      <pubDate>Thu, 23 Mar 2023 15:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/865962#M341980</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-03-23T15:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dataset by a variables value and exporting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/865970#M341984</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439355"&gt;@jmmedina252&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello, I have to sort the data by certain variables, like date as well before it is exported to excel. Is there a way I can do this with this code?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Include the date in the sort and have a matching BY statement in proc print. One sheet per combination of of the BY variables.&lt;/P&gt;
&lt;P&gt;If you have enough data you might run into spreadsheet limitations on the number of sheets.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/865970#M341984</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-23T15:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting dataset by a variables value and exporting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/866008#M342000</link>
      <description>&lt;P&gt;Just ask SAS to do it.&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
   by sex;
run;

ods excel file="c:\downloads\by_sex.xlsx"
 options(sheet_interval="BYGROUP"
         sheet_name="Sex=#byval(sex)"
        )
;
options nobyline;
proc print data=class noobs;
   by sex;
run;
ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1679608914752.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81962i093A35D0A7D0C628/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1679608914752.png" alt="Tom_0-1679608914752.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 22:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-dataset-by-a-variables-value-and-exporting/m-p/866008#M342000</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-23T22:02:02Z</dc:date>
    </item>
  </channel>
</rss>

