<?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: Creating a excel documents with multiple sheets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271980#M54104</link>
    <description>&lt;P&gt;Just mess around with the options provided in the link:&lt;/P&gt;
&lt;PRE&gt;options missing='';
ods listing close;
ods tagsets.excelxp file='s:\temp\rob\sample.xls' style=styles.statistical options(sheet_interval="Bygroup" suppress_bylines="yes" sheet_label=" ");

proc report data=sashelp.cars nowd nocenter;
  by make;
  columns model type origin Invoice;
  define model    / "Model" style(column)={cellwidth=200} style=[font_weight=bold];
  define type     / "type" style(column)={cellwidth=200};
  define origin   / "origin" style(column)={cellwidth=200};
  define Invoice  /"Invoice" style(column)={cellwidth=200};
run; 

ods tagsets.excelxp close;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 May 2016 13:37:18 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-05-20T13:37:18Z</dc:date>
    <item>
      <title>Creating a excel documents with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271954#M54096</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a problem with an output to excel from SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want my output to be one excel document with multiple sheets, and my thoughts were to use ods tagsets.excelxp with a proc report to define and put different styles on my variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It’s not a problem to use ods tagsets.excelxp if I know exactly how many sheets I need, my problem is that I don’t always know how many sheets I need when I get an order from a client.&lt;BR /&gt; And when I tried to put the code in a macro I failed and only get 1 sheet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have used the following code to get an output in the way I want it to be. To simplify my post I have used a dataset from the libname sashelp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And to solve my problem I would like to know how I put the following code so that each car model gets a sheet in a single Excel document.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options missing='';&lt;BR /&gt;ods listing close;&lt;BR /&gt;ods tagsets.excelxp file='C:/_localdata/sample.xls' style=styles.journal&lt;BR /&gt;options(sheet_name="Acura");&lt;BR /&gt;&lt;BR /&gt;proc report data=sashelp.cars nowd completerows contents="" nocenter&lt;BR /&gt;style(report)=[frame=above rules=groups cellspacing=1 font_size=1]&lt;BR /&gt;style(column)=[cellspacing=1 font_face=arial cellheight=28]&lt;BR /&gt;style(header)=[frame=hsides backgroundcolor=#99CCFF borderbottomcolor=black font_face=arial just=c];&lt;BR /&gt;where make="Acura";&lt;BR /&gt;columns make model type origin Invoice;&lt;BR /&gt;define make/"Make" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;define model/ "Model" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;define type/ "type" style(column)={cellwidth=200};&lt;BR /&gt;define origin/ "origin" style(column)={cellwidth=200};&lt;BR /&gt;define Invoice/"Invoice" style(column)={cellwidth=200};&lt;BR /&gt;run; quit;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;ods tagsets.excelxp options(sheet_name="Audi");&lt;BR /&gt;proc report data=sashelp.cars nowd completerows contents="" nocenter&lt;BR /&gt;style(report)=[frame=above rules=groups cellspacing=1 font_size=1]&lt;BR /&gt;style(column)=[cellspacing=1 font_face=arial cellheight=28]&lt;BR /&gt;style(header)=[frame=hsides backgroundcolor=#99CCFF borderbottomcolor=black font_face=arial just=c];&lt;BR /&gt;where make="Audi";&lt;BR /&gt;columns make model type origin Invoice;&lt;BR /&gt;define make/"Make" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;define model/ "Model" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;define type/ "type" style(column)={cellwidth=200};&lt;BR /&gt;define origin/ "origin" style(column)={cellwidth=200};&lt;BR /&gt;define Invoice/"Invoice" style(column)={cellwidth=200};&lt;BR /&gt;run; quit;&lt;BR /&gt;&lt;BR /&gt;ods tagsets.excelxp close;&lt;BR /&gt;ods listing;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Hannes&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271954#M54096</guid>
      <dc:creator>Sennahlake</dc:creator>
      <dc:date>2016-05-20T12:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a excel documents with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271960#M54099</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firstly the solution you want is to use by group processing and the sheet_interval option:&lt;/P&gt;
&lt;PRE&gt;options missing='';
ods listing close;
ods tagsets.excelxp file='C:/_localdata/sample.xls' style=styles.journal options(sheet_interval="Bygroup");

proc report data=sashelp.cars nowd completerows contents="" nocenter
            style(report)=[frame=above rules=groups cellspacing=1 font_size=1]
            style(column)=[cellspacing=1 font_face=arial cellheight=28]
            style(header)=[frame=hsides backgroundcolor=#99CCFF borderbottomcolor=black font_face=arial just=c];
  by make;
  columns model type origin Invoice;
  define model/ "Model" style(column)={cellwidth=200} style=[font_weight=bold];
  define type/ "type" style(column)={cellwidth=200};
  define origin/ "origin" style(column)={cellwidth=200};
  define Invoice/"Invoice" style(column)={cellwidth=200};
run; 

ods tagsets.excelxp close;&lt;/PRE&gt;
&lt;P&gt;All options can be found in the documentation:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html" target="_blank"&gt;https://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also do it with a data _null_ call execute() setup, but that is more complicated, and only for certain situations. &amp;nbsp;Why do you not know up front how many sheets there are, surely you have the data? &amp;nbsp;I wouldn't recommend a macro for this, you will spend more time maintaing that than just typing out some code.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271960#M54099</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-20T12:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a excel documents with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271975#M54102</link>
      <description>&lt;P&gt;Thanks, this solution worked really well, but I would prefer not to have "Make=Audi" in the example. I would like to have the solution of just having "Audi", do you know that this is possible?&lt;/P&gt;
&lt;P&gt;Also, the rows that were for example in the first group (Make=Audi) are now blank in the next sheet. Is there a way to remove these so that it just shows the group that is selected? I've included two pictures to show what I mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well I know how many sheet I have to work with, but not when I'm testing my code, as this is for a future project.&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12564iE9675602801F697E/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Make=Acura.JPG" title="Make=Acura.JPG" /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12565iC6BCB9792C4EAD09/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Make=Audi.JPG" title="Make=Audi.JPG" /&gt;</description>
      <pubDate>Fri, 20 May 2016 13:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271975#M54102</guid>
      <dc:creator>Sennahlake</dc:creator>
      <dc:date>2016-05-20T13:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a excel documents with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271980#M54104</link>
      <description>&lt;P&gt;Just mess around with the options provided in the link:&lt;/P&gt;
&lt;PRE&gt;options missing='';
ods listing close;
ods tagsets.excelxp file='s:\temp\rob\sample.xls' style=styles.statistical options(sheet_interval="Bygroup" suppress_bylines="yes" sheet_label=" ");

proc report data=sashelp.cars nowd nocenter;
  by make;
  columns model type origin Invoice;
  define model    / "Model" style(column)={cellwidth=200} style=[font_weight=bold];
  define type     / "type" style(column)={cellwidth=200};
  define origin   / "origin" style(column)={cellwidth=200};
  define Invoice  /"Invoice" style(column)={cellwidth=200};
run; 

ods tagsets.excelxp close;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 May 2016 13:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271980#M54104</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-20T13:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a excel documents with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271998#M54109</link>
      <description>&lt;P&gt;Thanks alot for the solution!&lt;/P&gt;
&lt;P&gt;But just one last thing&lt;/P&gt;
&lt;P&gt;Is it posible to add another table in the same sheet?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For example, I have tried to use the following code, but the tables appear in different sheets (Audi, Acura[..], Audi2, Acura2...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options missing='';&lt;BR /&gt;ods listing close;&lt;BR /&gt;ods tagsets.excelxp file='s:\temp\rob\sample.xls'&lt;BR /&gt;style=styles.journal options(sheet_interval="Bygroup" &lt;BR /&gt;suppress_bylines="yes" sheet_label=" ");&lt;BR /&gt;&lt;BR /&gt;proc report data=sashelp.cars nowd nocenter&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; style(report)=[frame=above rules=groups cellspacing=1 font_size=1]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; style(column)=[cellspacing=1 font_face=arial cellheight=28]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; style(header)=[frame=hsides backgroundcolor=#99CCFF borderbottomcolor=black font_face=arial just=c];&lt;BR /&gt;&amp;nbsp; by make;&lt;BR /&gt;&amp;nbsp; columns model type origin Invoice;&lt;BR /&gt;&amp;nbsp; define model/ "Model" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;&amp;nbsp; define type/ "type" style(column)={cellwidth=200};&lt;BR /&gt;&amp;nbsp; define origin/ "origin" style(column)={cellwidth=200};&lt;BR /&gt;&amp;nbsp; define Invoice/"Invoice" style(column)={cellwidth=200};&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc report data=sashelp.cars nowd nocenter&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; style(report)=[frame=above rules=groups cellspacing=1 font_size=1]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; style(column)=[cellspacing=1 font_face=arial cellheight=28]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; style(header)=[frame=hsides backgroundcolor=#99CCFF borderbottomcolor=black font_face=arial just=c];&lt;BR /&gt;&amp;nbsp; by make;&lt;BR /&gt;&amp;nbsp; columns model Horsepower MPG_City MPG_Highway Weight;&lt;BR /&gt;&amp;nbsp; define model/ "Model" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;&amp;nbsp; define Horsepower/ "Horsepower" style(column)={cellwidth=200} style=[font_weight=bold];&lt;BR /&gt;&amp;nbsp; define MPG_City/ "MPG_City" style(column)={cellwidth=200};&lt;BR /&gt;&amp;nbsp; define MPG_Highway/ "MPG_Highway" style(column)={cellwidth=200};&lt;BR /&gt;&amp;nbsp; define Weight/"Weight" style(column)={cellwidth=200};&lt;BR /&gt;run; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;ods tagsets.excelxp close;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 14:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/271998#M54109</guid>
      <dc:creator>Sennahlake</dc:creator>
      <dc:date>2016-05-20T14:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a excel documents with multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/272201#M54145</link>
      <description>&lt;P&gt;The option&lt;/P&gt;
&lt;P&gt;sheet_interval="Bygroup"&lt;/P&gt;
&lt;P&gt;is what places each BY group table on a separate sheet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are contemplating having a specific subsiet , say 3 makes on one page you would be best off adding a separate group variable and a PAGE variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only want two tables then instead sheet_intervl="BYGROUP" use "PROC" and a where clause to subset the data. Which is cumbersome if you are trying to create groups, see previouls line on adding group variable.&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 22:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-excel-documents-with-multiple-sheets/m-p/272201#M54145</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-20T22:48:42Z</dc:date>
    </item>
  </channel>
</rss>

