<?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: Using Formulas with ODS EXCEL ends up in a damaged excel file in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321316#M17608</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SAS Forum: Using Formulas with ODS EXCEL ends up in a damaged excel file

You might get a much faster response if you cross post to SAS-L

inspired by
http://tinyurl.com/z8mt4uo
https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321085

HAVE excel sheet

 +-------------------------+
 | EXCEL|    A          B  |
 |      |                  |
 |  ROW |   NAME       AGE |
 |      |                  |
 |    1 |   Alfred     14  |
 |    2 |   Alice      13  |
 |    3 |   Barbara    13  |
 |    4 |   Carol      14  |
 |    5 |   Henry      14  |
 +-------------------------+


WANT

 +--------------------------------+
 | EXCEL|    A          B     C   |
 |      |                         |
 |  ROW |   NAME       AGE   AGE2 |
 |      |                         |
 |    1 |   Alfred     14    14   |
 |    2 |   Alice      13    13   |
 |    3 |   Barbara    13    13   |
 |    4 |   Carol      14    14   |
 |    5 |   Henry      14    14   |
 +--------------------------------+


SOLUTION (Win 7 64 SAS9.4M2)


%utlfkil(d:\xls\formulax.xlsx);  * delete;
ods excel file='d:\xls\formulax.xlsx';
proc report data=sashelp.class(keep=name age);
column name age age2;
define age2 / "AGE2"
computed format=3. style={tagattr="formula:(RC[-1])"};
compute age2;
   age2=0;
endcomp;
run;
ods excel close;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 27 Dec 2016 19:02:18 GMT</pubDate>
    <dc:creator>rogerjdeangelis</dc:creator>
    <dc:date>2016-12-27T19:02:18Z</dc:date>
    <item>
      <title>Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321085#M17583</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem using formulas with ODS EXCEL. I'm trying to implement a chain-ladder method using formulas in my excel output. I don't want to calculate the future values in SAS, because&amp;nbsp;the calculation method should be documented within the excel file. Everything works perfectly, but there seems to be a general problem using formulas with ODS EXCEL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I reference another column in the same row ( e.g.&amp;nbsp;RC[-1] ) it just works. A reference to&amp;nbsp;another row in the same column ( e.g.&amp;nbsp;R[-1]C ) also works without problems. But as soon as I reference&amp;nbsp;another&amp;nbsp;row and another column ( e.g.&amp;nbsp;R[-1]C[-1] ) this ends up in a damaged excel file. Unfortunately this kind of formula is what I need for the chain-ladder method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the same with ODS TAGSETS.EXCELXP and there is no problem with formulas like&amp;nbsp;R[-1]C[-1], it just works perfectly. Unfortunately I can't switch to TAGSETS because I'm using some features that are only available with ODS EXCEL (e.g. writing output&amp;nbsp;to different sheets).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know&amp;nbsp;what I'm doing wrong or if this is&amp;nbsp;a known bug in ODS EXCEL?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here some simple code to reproduce the problem. Try the three different kinds of formulas by commenting the other two lines, the last one ends up in a damaged excel file. Change ODS EXCEL to ODS TAGSETS.EXCELXP and everything works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.test;
set sashelp.class;
attrib age2 format=3. label="Age2";
age2 = 0; * default value - formulas are not created in cells with missing values;
keep name age age2;
run;

ods excel file="/folders/myfolders/formula_test.xlsx" style=htmlBlue;

proc print data=test noobs label;
id name;
var age / style={TAGATTR='format:0'};
var age2 / style={TAGATTR='format:0 formula:RC[-1]'}; * this works;
*var age2 / style={TAGATTR='formula:R[-1]C'}; * this works;
*var age2 / style={TAGATTR='format:0 formula:R[-1]C[-1]'}; * this ends up in a damaged excel file;
run;

ods excel close;&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 13:29:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321085#M17583</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2016-12-25T13:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321088#M17584</link>
      <description>&lt;P&gt;ODS tagset also supports multiple sheets.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ODS EXCEL also supports formulas that are in the standard Excel format, ie E1 references.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings16/SAS5642-2016.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings16/SAS5642-2016.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2016 14:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321088#M17584</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-25T14:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321140#M17597</link>
      <description>&lt;P&gt;What SAS version are you using? I'm pretty sure ODS Excel only went production with 9.4M3. M4 has just been released and might be worth checking out to see if it fixes your problems.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2016 05:38:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321140#M17597</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2016-12-26T05:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321176#M17599</link>
      <description>&lt;P&gt;Thank you. Your are right, I completely forgot&amp;nbsp;that it was already possible to create multiple sheets with ods tagsets. I will have to check if there is any other reason that prevents me to use ods tagsets instead of ods excel.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2016 12:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321176#M17599</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2016-12-26T12:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321177#M17600</link>
      <description>&lt;P&gt;I think it is 9.4M3. I just had a look at the release notes of M4 and it seems that some other bugs I detected with ods excel have also been fixed with this release. Perhaps it is also the case for the excel formulas. I will to talk to our IT people when I'm back in the office.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2016 13:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321177#M17600</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2016-12-26T13:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321316#M17608</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SAS Forum: Using Formulas with ODS EXCEL ends up in a damaged excel file

You might get a much faster response if you cross post to SAS-L

inspired by
http://tinyurl.com/z8mt4uo
https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321085

HAVE excel sheet

 +-------------------------+
 | EXCEL|    A          B  |
 |      |                  |
 |  ROW |   NAME       AGE |
 |      |                  |
 |    1 |   Alfred     14  |
 |    2 |   Alice      13  |
 |    3 |   Barbara    13  |
 |    4 |   Carol      14  |
 |    5 |   Henry      14  |
 +-------------------------+


WANT

 +--------------------------------+
 | EXCEL|    A          B     C   |
 |      |                         |
 |  ROW |   NAME       AGE   AGE2 |
 |      |                         |
 |    1 |   Alfred     14    14   |
 |    2 |   Alice      13    13   |
 |    3 |   Barbara    13    13   |
 |    4 |   Carol      14    14   |
 |    5 |   Henry      14    14   |
 +--------------------------------+


SOLUTION (Win 7 64 SAS9.4M2)


%utlfkil(d:\xls\formulax.xlsx);  * delete;
ods excel file='d:\xls\formulax.xlsx';
proc report data=sashelp.class(keep=name age);
column name age age2;
define age2 / "AGE2"
computed format=3. style={tagattr="formula:(RC[-1])"};
compute age2;
   age2=0;
endcomp;
run;
ods excel close;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Dec 2016 19:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321316#M17608</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2016-12-27T19:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321334#M17610</link>
      <description>&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;Please open a ticket with our Technical Support Department:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;&lt;A href="http://support.sas.com/ctx/supportform/createForm" target="_blank"&gt;http://support.sas.com/ctx/supportform/createForm&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;The problem seems to be only partially corrected in the fourth maintenance for SAS 9.4.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;Vince DelGobbo&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;SAS R&amp;amp;D&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Dec 2016 20:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321334#M17610</guid>
      <dc:creator>Vince_SAS</dc:creator>
      <dc:date>2016-12-27T20:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321397#M17612</link>
      <description>&lt;P&gt;Thank you, but there is no problem with formulas like RC[-1]. I tried your code with the formula R[-1]C[-1] and it also leads to a damaged excel file.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2016 08:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/321397#M17612</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2016-12-28T08:31:28Z</dc:date>
    </item>
    <item>
      <title>Betreff: Using Formulas with ODS EXCEL ends up in a damaged excel file</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/323167#M17693</link>
      <description>&lt;P&gt;This week I had contact to SAS Technical Support. The answer was that this is an already known issue, but unfortunately there's no hotfix available yet. Also SAS 9.4 M4 doesn't fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By now&amp;nbsp;I found two possible workarounds to use until it is fixed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Use&amp;nbsp;ODS TAGSETS.EXCELXP instead of ODS EXCEL as long as there's no need for any features that are exclusively available for ODS EXCEL (e.g. embedding graphics).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;With ODS EXCEL&amp;nbsp;it is also possible to create the formulas by using the INDIRECT functionality of&amp;nbsp;excel. Unfortunately this leads to longer and more complex formulas. The formulas created in excel are also not&amp;nbsp;as&amp;nbsp;easy to understand as a normal&amp;nbsp;direct formula, because for indirect formulas excel will not highlight the cells used for the calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my case I would normally use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'format:0.00% formula:MAX(RC[-1]+AVERAGE(R[-4]C:R[-1]C)-AVERAGE(R[-4]C[-1]:R[-1]C[-1]),0)'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For e.g. cell C6 excel would show the following formula&lt;/P&gt;&lt;P&gt;=MAX(B6+AVERAGE(C2:C5)-AVERAGE(B2:B5),0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the indirect formula it is now:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'format:0.00% formula:MAX(INDIRECT(ADDRESS(ROW(),COLUMN()-1))
+AVERAGE(INDIRECT(ADDRESS(ROW()-4,COLUMN())):INDIRECT(ADDRESS(ROW()-1,COLUMN())))
-AVERAGE(INDIRECT(ADDRESS(ROW()-4,COLUMN()-1)):INDIRECT(ADDRESS(ROW()-1,COLUMN()-1))),0)'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For e.g. cell C6 excel shows now the following formula&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;=MAX(INDIRECT(ADDRESS(ROW(),COLUMN()-1))+AVERAGE(INDIRECT(ADDRESS(ROW()-4,COLUMN())):INDIRECT(ADDRESS(ROW()-1,COLUMN())))-AVERAGE(INDIRECT(ADDRESS(ROW()-4,COLUMN()-1)):INDIRECT(ADDRESS(ROW()-1,COLUMN()-1))),0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Jan 2017 18:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Using-Formulas-with-ODS-EXCEL-ends-up-in-a-damaged-excel-file/m-p/323167#M17693</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2017-01-07T18:12:37Z</dc:date>
    </item>
  </channel>
</rss>

