<?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 Add sheets to existing excel file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/710374#M218664</link>
    <description>&lt;P&gt;Hi, I would like to know it is possible to add sheets generated by ods excel onto an existing excel file which has the first sheet filled?&lt;/P&gt;&lt;P&gt;My reports are being generated by proc statements, so i can't use proc export as I don't have output tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is how my code looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname pg1 "/folders/myfolders/EPG1V2/data";&lt;BR /&gt;%let outpath=/folders/myfolders/EPG1V2/data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;title;&lt;/P&gt;&lt;P&gt;ods excel file="&amp;amp;outpath/UAT_Blah_20201229.xlsx"&lt;BR /&gt;style=excel&lt;BR /&gt;options(embedded_titles='yes'&lt;BR /&gt;sheet_name='Test 1' sheet_interval='none');&lt;BR /&gt;&lt;BR /&gt;proc contents data=pg1.storm_final varnum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel options(sheet_name='Test 2');&lt;/P&gt;&lt;P&gt;proc surveyselect data=pg1.storm_final out=table method=srs&lt;BR /&gt;sampsize=10 seed=1234567 noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=table;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods excel options(sheet_name='Test 3' sheet_interval='none');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prep_stats(v_base,v_group);&lt;/P&gt;&lt;P&gt;title "Contents of &amp;amp;v_base";&lt;BR /&gt;&lt;BR /&gt;proc contents data=&amp;amp;v_base out=storm_cols varnum noprint;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data v_base2 noprint;&lt;BR /&gt;set &amp;amp;v_base;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title "Frequency of &amp;amp;v_base BY &amp;amp;v_group";&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;&amp;amp;v_group,&lt;BR /&gt;count(*) as count&lt;BR /&gt;from v_base2&lt;BR /&gt;group by &amp;amp;v_group;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;title "Numeric Stats of &amp;amp;v_base";&lt;BR /&gt;&lt;BR /&gt;proc means data=v_base2 n nmiss min max sum;&lt;BR /&gt;var _numeric_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title "Date Stats of &amp;amp;v_base";&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select NAME into :datevars separated by ' ' /*NAME contain column/variable names*/&lt;BR /&gt;from storm_cols&lt;BR /&gt;where format = 'DATE';&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc tabulate data=v_base2;&lt;BR /&gt;var &amp;amp;datevars;&lt;BR /&gt;table&lt;BR /&gt;/*ROW*/&lt;BR /&gt;&amp;amp;datevars,&lt;BR /&gt;/*COLUMN*/&lt;BR /&gt;(n nmiss (min max)*f=yymmdd10.);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title "Number of Character Columns";&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table tmp_char as&lt;BR /&gt;select *&lt;BR /&gt;from storm_cols&lt;BR /&gt;where format="$CHAR";&lt;BR /&gt;&lt;BR /&gt;/*Get total count of character columns*/&lt;BR /&gt;select count(*) into: Ncols&lt;BR /&gt;from tmp_char;&lt;BR /&gt;&lt;BR /&gt;/*Get list of character column names*/&lt;BR /&gt;select NAME into :NAME1-:NAME%Left(&amp;amp;Ncols)&lt;BR /&gt;from tmp_char;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;Ncols;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select count(distinct &amp;amp;&amp;amp;NAME&amp;amp;i) into :d_cnt&lt;BR /&gt;from v_base2;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;d_cnt&amp;lt;=100 %then /* if no of records less than 100 then run do */&lt;BR /&gt;%do;&lt;BR /&gt;title "Unique Count of &amp;amp;&amp;amp;NAME&amp;amp;i";&lt;BR /&gt;/*List of counts for each element in each character column*/&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;&amp;amp;&amp;amp;NAME&amp;amp;i,&lt;BR /&gt;count(*) as cnt&lt;BR /&gt;from v_base2&lt;BR /&gt;group by &amp;amp;&amp;amp;NAME&amp;amp;i&lt;BR /&gt;order by &amp;amp;&amp;amp;NAME&amp;amp;i;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%prep_stats(pg1.storm_final,StartDate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel close;&lt;/P&gt;</description>
    <pubDate>Sat, 09 Jan 2021 13:54:24 GMT</pubDate>
    <dc:creator>huiyi213</dc:creator>
    <dc:date>2021-01-09T13:54:24Z</dc:date>
    <item>
      <title>Add sheets to existing excel file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/710374#M218664</link>
      <description>&lt;P&gt;Hi, I would like to know it is possible to add sheets generated by ods excel onto an existing excel file which has the first sheet filled?&lt;/P&gt;&lt;P&gt;My reports are being generated by proc statements, so i can't use proc export as I don't have output tables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is how my code looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname pg1 "/folders/myfolders/EPG1V2/data";&lt;BR /&gt;%let outpath=/folders/myfolders/EPG1V2/data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;title;&lt;/P&gt;&lt;P&gt;ods excel file="&amp;amp;outpath/UAT_Blah_20201229.xlsx"&lt;BR /&gt;style=excel&lt;BR /&gt;options(embedded_titles='yes'&lt;BR /&gt;sheet_name='Test 1' sheet_interval='none');&lt;BR /&gt;&lt;BR /&gt;proc contents data=pg1.storm_final varnum;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel options(sheet_name='Test 2');&lt;/P&gt;&lt;P&gt;proc surveyselect data=pg1.storm_final out=table method=srs&lt;BR /&gt;sampsize=10 seed=1234567 noprint;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=table;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods excel options(sheet_name='Test 3' sheet_interval='none');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro prep_stats(v_base,v_group);&lt;/P&gt;&lt;P&gt;title "Contents of &amp;amp;v_base";&lt;BR /&gt;&lt;BR /&gt;proc contents data=&amp;amp;v_base out=storm_cols varnum noprint;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data v_base2 noprint;&lt;BR /&gt;set &amp;amp;v_base;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title "Frequency of &amp;amp;v_base BY &amp;amp;v_group";&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;&amp;amp;v_group,&lt;BR /&gt;count(*) as count&lt;BR /&gt;from v_base2&lt;BR /&gt;group by &amp;amp;v_group;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;title "Numeric Stats of &amp;amp;v_base";&lt;BR /&gt;&lt;BR /&gt;proc means data=v_base2 n nmiss min max sum;&lt;BR /&gt;var _numeric_;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title "Date Stats of &amp;amp;v_base";&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select NAME into :datevars separated by ' ' /*NAME contain column/variable names*/&lt;BR /&gt;from storm_cols&lt;BR /&gt;where format = 'DATE';&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc tabulate data=v_base2;&lt;BR /&gt;var &amp;amp;datevars;&lt;BR /&gt;table&lt;BR /&gt;/*ROW*/&lt;BR /&gt;&amp;amp;datevars,&lt;BR /&gt;/*COLUMN*/&lt;BR /&gt;(n nmiss (min max)*f=yymmdd10.);&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;title "Number of Character Columns";&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table tmp_char as&lt;BR /&gt;select *&lt;BR /&gt;from storm_cols&lt;BR /&gt;where format="$CHAR";&lt;BR /&gt;&lt;BR /&gt;/*Get total count of character columns*/&lt;BR /&gt;select count(*) into: Ncols&lt;BR /&gt;from tmp_char;&lt;BR /&gt;&lt;BR /&gt;/*Get list of character column names*/&lt;BR /&gt;select NAME into :NAME1-:NAME%Left(&amp;amp;Ncols)&lt;BR /&gt;from tmp_char;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;Ncols;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select count(distinct &amp;amp;&amp;amp;NAME&amp;amp;i) into :d_cnt&lt;BR /&gt;from v_base2;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;d_cnt&amp;lt;=100 %then /* if no of records less than 100 then run do */&lt;BR /&gt;%do;&lt;BR /&gt;title "Unique Count of &amp;amp;&amp;amp;NAME&amp;amp;i";&lt;BR /&gt;/*List of counts for each element in each character column*/&lt;BR /&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;&amp;amp;&amp;amp;NAME&amp;amp;i,&lt;BR /&gt;count(*) as cnt&lt;BR /&gt;from v_base2&lt;BR /&gt;group by &amp;amp;&amp;amp;NAME&amp;amp;i&lt;BR /&gt;order by &amp;amp;&amp;amp;NAME&amp;amp;i;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%prep_stats(pg1.storm_final,StartDate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ods excel close;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 13:54:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/710374#M218664</guid>
      <dc:creator>huiyi213</dc:creator>
      <dc:date>2021-01-09T13:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add sheets to existing excel file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/710403#M218683</link>
      <description>&lt;P&gt;Unfortunately not. The ODS approach requires that you build your Excel workbook from scratch each time. This is because ODS allows you to do output highly-formatted data that would be too difficult to interpret if you were adding sheets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution is to use either the XLSX LIBNAME or PROC EXPORT using DBMS = XLSX. This will require you to build your worksheets as SAS datasets first before exporting them.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jan 2021 22:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/710403#M218683</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-01-09T22:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Add sheets to existing excel file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/711010#M218958</link>
      <description>Oh okayy, thanks for your help anyway!</description>
      <pubDate>Wed, 13 Jan 2021 08:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-sheets-to-existing-excel-file/m-p/711010#M218958</guid>
      <dc:creator>huiyi213</dc:creator>
      <dc:date>2021-01-13T08:18:01Z</dc:date>
    </item>
  </channel>
</rss>

