<?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 Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889930#M351610</link>
    <description>&lt;P&gt;I have 1 SAS dataset of 8 unique customer IDs and want to export each unique ID to a separate Excel worksheet.&amp;nbsp; I also want to add the same visible title to each worksheet.&amp;nbsp; I've got code that does one or the other but not both.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* create sample dataset*/&lt;/P&gt;&lt;P&gt;data sample;&lt;BR /&gt;input ID $ Name $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 John&lt;BR /&gt;2 Jane&lt;BR /&gt;3 Michael&lt;BR /&gt;4 Emily&lt;BR /&gt;5 David&lt;BR /&gt;6 Sophia&lt;BR /&gt;7 James&lt;BR /&gt;8 Olivia&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* code to export each ID to a different worksheet*/&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select distinct ID into :category_list separated by ' '&lt;BR /&gt;from sample;&lt;BR /&gt;quit;&lt;BR /&gt;%macro export_to_excel;&lt;BR /&gt;%do i = 1 %to %sysfunc(countw(&amp;amp;category_list));&lt;BR /&gt;%let current_category = %scan(&amp;amp;category_list, &amp;amp;i);&lt;BR /&gt;&lt;BR /&gt;proc export data=sample(where=(ID="&amp;amp;current_category"))&lt;BR /&gt;outfile="c:\TEMP\test22.xlsx"&lt;BR /&gt;dbms=excel replace;&lt;BR /&gt;sheet="&amp;amp;current_category";&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%export_to_excel;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*code for exporting with format and 2 TITLE ROWS*/&lt;BR /&gt;/* export report */&lt;BR /&gt;ods escapechar="~";&lt;BR /&gt;ods excel file="c:\temp\test126.xlsx" options(sheet_name='Sheet1');&lt;BR /&gt;ods text="~{style[color=green fontstyle=italic] BANKRUPTCY CASE NO.";&lt;BR /&gt;ods text="~{style[color=green fontstyle=italic] FILED";&lt;/P&gt;&lt;P&gt;proc report data=work.sample/*(obs=5) */spanrows&lt;/P&gt;&lt;P&gt;style(report)={pretext=" "};&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired outcome would be: one customer per worksheet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="deblee73_0-1692376881362.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86821i2E9AA6327A0713E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="deblee73_0-1692376881362.png" alt="deblee73_0-1692376881362.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&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>Fri, 18 Aug 2023 16:41:47 GMT</pubDate>
    <dc:creator>deblee73</dc:creator>
    <dc:date>2023-08-18T16:41:47Z</dc:date>
    <item>
      <title>Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889930#M351610</link>
      <description>&lt;P&gt;I have 1 SAS dataset of 8 unique customer IDs and want to export each unique ID to a separate Excel worksheet.&amp;nbsp; I also want to add the same visible title to each worksheet.&amp;nbsp; I've got code that does one or the other but not both.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* create sample dataset*/&lt;/P&gt;&lt;P&gt;data sample;&lt;BR /&gt;input ID $ Name $;&lt;BR /&gt;datalines;&lt;BR /&gt;1 John&lt;BR /&gt;2 Jane&lt;BR /&gt;3 Michael&lt;BR /&gt;4 Emily&lt;BR /&gt;5 David&lt;BR /&gt;6 Sophia&lt;BR /&gt;7 James&lt;BR /&gt;8 Olivia&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* code to export each ID to a different worksheet*/&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select distinct ID into :category_list separated by ' '&lt;BR /&gt;from sample;&lt;BR /&gt;quit;&lt;BR /&gt;%macro export_to_excel;&lt;BR /&gt;%do i = 1 %to %sysfunc(countw(&amp;amp;category_list));&lt;BR /&gt;%let current_category = %scan(&amp;amp;category_list, &amp;amp;i);&lt;BR /&gt;&lt;BR /&gt;proc export data=sample(where=(ID="&amp;amp;current_category"))&lt;BR /&gt;outfile="c:\TEMP\test22.xlsx"&lt;BR /&gt;dbms=excel replace;&lt;BR /&gt;sheet="&amp;amp;current_category";&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%export_to_excel;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*code for exporting with format and 2 TITLE ROWS*/&lt;BR /&gt;/* export report */&lt;BR /&gt;ods escapechar="~";&lt;BR /&gt;ods excel file="c:\temp\test126.xlsx" options(sheet_name='Sheet1');&lt;BR /&gt;ods text="~{style[color=green fontstyle=italic] BANKRUPTCY CASE NO.";&lt;BR /&gt;ods text="~{style[color=green fontstyle=italic] FILED";&lt;/P&gt;&lt;P&gt;proc report data=work.sample/*(obs=5) */spanrows&lt;/P&gt;&lt;P&gt;style(report)={pretext=" "};&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;ods excel close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired outcome would be: one customer per worksheet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="deblee73_0-1692376881362.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/86821i2E9AA6327A0713E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="deblee73_0-1692376881362.png" alt="deblee73_0-1692376881362.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&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>Fri, 18 Aug 2023 16:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889930#M351610</guid>
      <dc:creator>deblee73</dc:creator>
      <dc:date>2023-08-18T16:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889946#M351617</link>
      <description>&lt;P&gt;Why not just use the ODS EXCEL option that will embed the titles into the sheet instead of putting it into the print header area of the sheet?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 17:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889946#M351617</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-18T17:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889962#M351628</link>
      <description>&lt;P&gt;Here's where I would start:&lt;/P&gt;
&lt;P&gt;BY groups are generally preferable to multiple subsets of data and calling a procedure multiple times.&lt;/P&gt;
&lt;P&gt;I used proc print as you didn't provide much of a "report" because of the reduced data. Proc Report will do by groups but, as with Print, you would have to explicitly add the BY variable(s) to the column definitions to place them in the body of the report.&lt;/P&gt;
&lt;P&gt;The system option NOBYLINE suppresses the default "By variable name= value" . Don't forget to reset the default behavior when done.&lt;/P&gt;
&lt;P&gt;Note that the TITLE statement has a fair number of options for appearance and will appear with each table generated.&lt;/P&gt;
&lt;P&gt;ODS TEXT appears only one time before the procedure output. The By group also allows use of the Sheet_interval to control output to one per sheet (in this case).&lt;/P&gt;
&lt;PRE&gt;/* sort by ID if needed*/

options nobyline;
ods excel file="c:\temp\by_example.xlsx"
   options(sheet_interval='BYGROUP');
title1 color=green italic "BANKRUPTCY CASE NO.";
title2 color=green italic "FILED";
proc print data=sample noobs;
   by id;
   var id name;
run;
title;
ods excel close;

/*reset default byline behavior*/
options byline;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 18:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889962#M351628</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-18T18:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889968#M351630</link>
      <description>&lt;P&gt;Thank&amp;nbsp; you, both.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first response I believe it what I need but not sure which of the two code samples to put it in and where in the code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second response does what I want except puts the titles in print preview rather than body of the sheet.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made a simple dataset just for demonstration purposes.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can live with the second one but the report I was asked to build had the titles in the body of the sheet as the first few rows.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 18:13:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889968#M351630</guid>
      <dc:creator>deblee73</dc:creator>
      <dc:date>2023-08-18T18:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889979#M351636</link>
      <description>&lt;P&gt;Look at the options for ODS Excel. One of them Embedded_titles='ON' should place the titles in the body of the sheet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options(sheet_interval='BYGROUP' Embedded_titles='ON')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's around 46 options. Please look some of them up on your own.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 19:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889979#M351636</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-18T19:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889980#M351637</link>
      <description>&lt;P&gt;The first example in the documentation covers everything in your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_042/odsug/p09n5pw9ol0897n1qe04zeur27rv.htm#n0bmw0v2sv7lepn17aovz1217r9k" target="_blank"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/v_042/odsug/p09n5pw9ol0897n1qe04zeur27rv.htm#n0bmw0v2sv7lepn17aovz1217r9k&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="xisDoc-listUnordered"&gt;
&lt;LI class="xisDoc-item"&gt;A new worksheet is created for each BY group.&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;The BY lines are suppressed.&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;The title created by the TITLE statement is embedded in the output.&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;The worksheet labels are customized.&lt;/LI&gt;
&lt;LI class="xisDoc-item"&gt;A blank worksheet with a custom tab is inserted after the last BY group. (not needed in your use case)&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 19:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889980#M351637</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-08-18T19:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889981#M351638</link>
      <description>&lt;P&gt;Perfection.&amp;nbsp; Thanks for sharing your knowledge.&amp;nbsp; Take Care!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 19:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889981#M351638</guid>
      <dc:creator>deblee73</dc:creator>
      <dc:date>2023-08-18T19:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Export 1 SAS dataset to multiple Excel worksheets with same title on each worksheet.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889982#M351639</link>
      <description>&lt;P&gt;Thank you for the link to the documentation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 19:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-1-SAS-dataset-to-multiple-Excel-worksheets-with-same/m-p/889982#M351639</guid>
      <dc:creator>deblee73</dc:creator>
      <dc:date>2023-08-18T19:49:41Z</dc:date>
    </item>
  </channel>
</rss>

