<?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: ODS HTML File in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14614#M3317</link>
    <description>Hi:&lt;BR /&gt;
  Switching to teacher mode here for a minute...when you use ODS HTML, you are not creating a "native" or true, binary .XLS file. You are creating an ASCII text file that Microsoft Excel knows how to open and render. Even if you name the file with a .XLS extension -- the file is still HTML and ASCII text, which you can prove to yourself by opening the file with Notepad. OK...teacher clarification moment over.&lt;BR /&gt;
&lt;BR /&gt;
  Because Excel is opening an HTML table into spreadsheet view, Excel makes some assumptions (in your data's case wrong assumptions), that it should try a general numeric format for numeric columns. Because 5-9 and 10-14 looked like dates, Excel displays them as it thinks you want.&lt;BR /&gt;
 &lt;BR /&gt;
  In order to "fix" the issue, you have to get Excel's attention and send it an instruction about how to format your column. With ODS HTML techniques for creating output for Excel, the method is to use the HTMLSTYLE style attribute with the MSO-NUMBER-FORMAT specification that you want. For example, if you wanted leading zeros for the variable PRODUCTID using PROC PRINT (VAR statement) or PROC REPORT (DEFINE statement), you would have:&lt;BR /&gt;
[pre]&lt;BR /&gt;
var productid / style(data)={htmlstyle="mso-number-format:0000000"};&lt;BR /&gt;
define productid / style(column)={htmlstyle="mso-number-format:0000000"};&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
If you were using PRODUCTID as a CLASS variable in PROC TABULATE, then your CLASSLEV statement would be:&lt;BR /&gt;
[pre]&lt;BR /&gt;
classlev productid / style={htmlstyle="mso-number-format:0000000"};&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Sometimes, Excel can be particularly frustrating -- such as with a single hyphen as you want in your string. If you run the program below, you will see that even instructing Microsoft Excel to treat the column as a TEXT format (\@), Excel ignores that format for the TESTCOL value for Alice and Alfred -- using any other separator or starting the value with a character other than space seems to finally get Excel to cooperate. Program shows using PROC REPORT, but syntax for PRINT, TABULATE is same as above.&lt;BR /&gt;
&lt;BR /&gt;
BTW, I used the ODS MSOFFICE2K destination because ODS HTML creates HTML 4.0 tags (which Excel isn't always happy using) in favor of the Microsoft-specific  HTML, as generated by ODS MSOFFICE2K. (History: When Microsoft disagreed with the W3C over the HTML specification, they formulated their own flavor of HTML.)&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data testit;&lt;BR /&gt;
length testcol $6;&lt;BR /&gt;
  set sashelp.class(keep=name age);&lt;BR /&gt;
  if name =: 'A' then&lt;BR /&gt;
     testcol=catx('-','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'B' then&lt;BR /&gt;
     testcol=catx('--','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'C' then&lt;BR /&gt;
     testcol=catx(':','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'H' then&lt;BR /&gt;
     testcol=catx('~','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'J' then&lt;BR /&gt;
     testcol=catx('*','5',put(age,2.0));&lt;BR /&gt;
  else testcol=catx('-','R 5',put(age,2.0));&lt;BR /&gt;
run;&lt;BR /&gt;
                             &lt;BR /&gt;
ods msoffice2k file='c:\temp\usehtmlstyle.xls' style=sasweb;&lt;BR /&gt;
                &lt;BR /&gt;
proc report data=testit nowd;&lt;BR /&gt;
title "The \@ instructs Excel to treat the cell as TEXT";&lt;BR /&gt;
title2 "But when you use a single - in the string does not work";&lt;BR /&gt;
title3 "See diff between Alfred and Alice and others";&lt;BR /&gt;
title4 "Almost any separator seems to work except a hyphen";&lt;BR /&gt;
  column name age testcol;&lt;BR /&gt;
  define name / 'Name';&lt;BR /&gt;
  define testcol / 'TestCol'&lt;BR /&gt;
         style(column)={HTMLSTYLE='text-align:left;mso-number-format:"\@"'};&lt;BR /&gt;
run;&lt;BR /&gt;
ods _all_ close;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Tue, 22 Feb 2011 16:12:40 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2011-02-22T16:12:40Z</dc:date>
    <item>
      <title>ODS HTML File</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14613#M3316</link>
      <description>I use ODS HTML to write a.xls file with a variable, say AGE_GP in a format 0-4, 5-9, 10-14, 15-19, ... An xls document is created, and the file is opened in Excel 2007, Excel will display the variable AGE_GP with the format 0-4, May.09, Oct.14, 15-19 not the range format 0-4, 5-9, 10-14, 15-19.  How to fix it. Thanks.&lt;BR /&gt;
&lt;BR /&gt;
FC</description>
      <pubDate>Tue, 22 Feb 2011 09:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14613#M3316</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-22T09:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: ODS HTML File</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14614#M3317</link>
      <description>Hi:&lt;BR /&gt;
  Switching to teacher mode here for a minute...when you use ODS HTML, you are not creating a "native" or true, binary .XLS file. You are creating an ASCII text file that Microsoft Excel knows how to open and render. Even if you name the file with a .XLS extension -- the file is still HTML and ASCII text, which you can prove to yourself by opening the file with Notepad. OK...teacher clarification moment over.&lt;BR /&gt;
&lt;BR /&gt;
  Because Excel is opening an HTML table into spreadsheet view, Excel makes some assumptions (in your data's case wrong assumptions), that it should try a general numeric format for numeric columns. Because 5-9 and 10-14 looked like dates, Excel displays them as it thinks you want.&lt;BR /&gt;
 &lt;BR /&gt;
  In order to "fix" the issue, you have to get Excel's attention and send it an instruction about how to format your column. With ODS HTML techniques for creating output for Excel, the method is to use the HTMLSTYLE style attribute with the MSO-NUMBER-FORMAT specification that you want. For example, if you wanted leading zeros for the variable PRODUCTID using PROC PRINT (VAR statement) or PROC REPORT (DEFINE statement), you would have:&lt;BR /&gt;
[pre]&lt;BR /&gt;
var productid / style(data)={htmlstyle="mso-number-format:0000000"};&lt;BR /&gt;
define productid / style(column)={htmlstyle="mso-number-format:0000000"};&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
If you were using PRODUCTID as a CLASS variable in PROC TABULATE, then your CLASSLEV statement would be:&lt;BR /&gt;
[pre]&lt;BR /&gt;
classlev productid / style={htmlstyle="mso-number-format:0000000"};&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Sometimes, Excel can be particularly frustrating -- such as with a single hyphen as you want in your string. If you run the program below, you will see that even instructing Microsoft Excel to treat the column as a TEXT format (\@), Excel ignores that format for the TESTCOL value for Alice and Alfred -- using any other separator or starting the value with a character other than space seems to finally get Excel to cooperate. Program shows using PROC REPORT, but syntax for PRINT, TABULATE is same as above.&lt;BR /&gt;
&lt;BR /&gt;
BTW, I used the ODS MSOFFICE2K destination because ODS HTML creates HTML 4.0 tags (which Excel isn't always happy using) in favor of the Microsoft-specific  HTML, as generated by ODS MSOFFICE2K. (History: When Microsoft disagreed with the W3C over the HTML specification, they formulated their own flavor of HTML.)&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
data testit;&lt;BR /&gt;
length testcol $6;&lt;BR /&gt;
  set sashelp.class(keep=name age);&lt;BR /&gt;
  if name =: 'A' then&lt;BR /&gt;
     testcol=catx('-','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'B' then&lt;BR /&gt;
     testcol=catx('--','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'C' then&lt;BR /&gt;
     testcol=catx(':','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'H' then&lt;BR /&gt;
     testcol=catx('~','5',put(age,2.0));&lt;BR /&gt;
  else if name =: 'J' then&lt;BR /&gt;
     testcol=catx('*','5',put(age,2.0));&lt;BR /&gt;
  else testcol=catx('-','R 5',put(age,2.0));&lt;BR /&gt;
run;&lt;BR /&gt;
                             &lt;BR /&gt;
ods msoffice2k file='c:\temp\usehtmlstyle.xls' style=sasweb;&lt;BR /&gt;
                &lt;BR /&gt;
proc report data=testit nowd;&lt;BR /&gt;
title "The \@ instructs Excel to treat the cell as TEXT";&lt;BR /&gt;
title2 "But when you use a single - in the string does not work";&lt;BR /&gt;
title3 "See diff between Alfred and Alice and others";&lt;BR /&gt;
title4 "Almost any separator seems to work except a hyphen";&lt;BR /&gt;
  column name age testcol;&lt;BR /&gt;
  define name / 'Name';&lt;BR /&gt;
  define testcol / 'TestCol'&lt;BR /&gt;
         style(column)={HTMLSTYLE='text-align:left;mso-number-format:"\@"'};&lt;BR /&gt;
run;&lt;BR /&gt;
ods _all_ close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 22 Feb 2011 16:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14614#M3317</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-02-22T16:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: ODS HTML File</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14615#M3318</link>
      <description>Thank you very much.</description>
      <pubDate>Wed, 23 Feb 2011 09:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-HTML-File/m-p/14615#M3318</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-23T09:24:35Z</dc:date>
    </item>
  </channel>
</rss>

