<?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 How to export a single table into multiple Excel sheets? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-export-a-single-table-into-multiple-Excel-sheets/m-p/343206#M78782</link>
    <description>&lt;P&gt;Hey!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am kinda new to the SAS Base Programming, and I just want to learn it as much as I can. Thus I did some exercises, but I got stucked in a problem. I have a huge table with full of datas about cars. I have to sort them by "make" wich means that I have to categorize the car types. There are 38 types of cars (Azura - 1, Audi - 2 ect). After It I have to export the whole table by a macro. But each type (1, 2, 3, 4 ect) should be on different sheets. And there is the problem. How to export a single table, with one macro to multiple sheets by type?&lt;/P&gt;&lt;P&gt;Here is the code, it might help you understand what I did:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro sort;
proc sort data = sashelp.cars out= test.cars;
by Make;
run;
%mend;

%macro set;
data test.cars_sorted (rename=count=uniqid); &amp;lt;-- make them into groups
set test.cars;
by Make;
if first.make then count+1;
else count=count;
run;
%mend;

%macro export(x);
proc export data = test.cars_sorted
outfile = "D:\&amp;amp;x."
dbms = XLSX replace;
sheet = "car_uniqid"; &amp;lt;-- It should make them into sheets like "car_1".
run;
%mend export;


%sort;
%set;
%export(cars);&lt;/PRE&gt;&lt;P&gt;Can you guys help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Mar 2017 08:56:50 GMT</pubDate>
    <dc:creator>Derdavos</dc:creator>
    <dc:date>2017-03-22T08:56:50Z</dc:date>
    <item>
      <title>How to export a single table into multiple Excel sheets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-export-a-single-table-into-multiple-Excel-sheets/m-p/343206#M78782</link>
      <description>&lt;P&gt;Hey!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am kinda new to the SAS Base Programming, and I just want to learn it as much as I can. Thus I did some exercises, but I got stucked in a problem. I have a huge table with full of datas about cars. I have to sort them by "make" wich means that I have to categorize the car types. There are 38 types of cars (Azura - 1, Audi - 2 ect). After It I have to export the whole table by a macro. But each type (1, 2, 3, 4 ect) should be on different sheets. And there is the problem. How to export a single table, with one macro to multiple sheets by type?&lt;/P&gt;&lt;P&gt;Here is the code, it might help you understand what I did:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro sort;
proc sort data = sashelp.cars out= test.cars;
by Make;
run;
%mend;

%macro set;
data test.cars_sorted (rename=count=uniqid); &amp;lt;-- make them into groups
set test.cars;
by Make;
if first.make then count+1;
else count=count;
run;
%mend;

%macro export(x);
proc export data = test.cars_sorted
outfile = "D:\&amp;amp;x."
dbms = XLSX replace;
sheet = "car_uniqid"; &amp;lt;-- It should make them into sheets like "car_1".
run;
%mend export;


%sort;
%set;
%export(cars);&lt;/PRE&gt;&lt;P&gt;Can you guys help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 08:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-export-a-single-table-into-multiple-Excel-sheets/m-p/343206#M78782</guid>
      <dc:creator>Derdavos</dc:creator>
      <dc:date>2017-03-22T08:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to export a single table into multiple Excel sheets?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-export-a-single-table-into-multiple-Excel-sheets/m-p/343212#M78783</link>
      <description>&lt;P&gt;Okay everyone!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found the answer. &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is the code:&lt;/P&gt;&lt;PRE&gt;%macro sort;
proc sort data = sashelp.cars out= test.cars;
by Make;
run;
%mend;

%sort;

%macro set;
data test.cars_sorted (rename=count=uniqid);
set test.cars;
by Make;
if first.make then count+1;
else count=count;
run;
%mend;

%set;

%macro multisheet (x);
proc sql noprint;
select distinct uniqid 
into :carid1 - :carid38
from test.cars_sorted;
%let type = &amp;amp;sqlobs;
quit;
 
%do i = 1 %to &amp;amp;type;
proc export data = test.cars_sorted(where=(uniqid=&amp;amp;&amp;amp;carid&amp;amp;i))
outfile="D:\Munka\&amp;amp;x."
dbms= xlsx replace;
sheet = "car_&amp;amp;&amp;amp;carid&amp;amp;i";
run;
%end;
%mend multisheet;

%multisheet(cars);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Mar 2017 09:15:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-export-a-single-table-into-multiple-Excel-sheets/m-p/343212#M78783</guid>
      <dc:creator>Derdavos</dc:creator>
      <dc:date>2017-03-22T09:15:37Z</dc:date>
    </item>
  </channel>
</rss>

