BookmarkSubscribeRSS Feed
qkaiwei
Calcite | Level 5
Anyone who can give me an ODS example that exports gif/jpg producted by SAS/Graph to Excel.
each gif/jgp each worksheet! gif/jpg and also datatable same in one worksheet will be better!

Thanks in Adv!
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
There's good news and bad news about what you want to do.

The good news is that ODS Tagsets.ExcelXP automatically creates multiple worksheet workbooks in Excel. The bad news is that by Microsoft design/specification Spreadsheet ML (Excel XML) does NOT support graphs. If you try to create graphs in an ExcelXP output file, you get this message in the log:
[pre]
Excel XML does not support output from Proc:Gchart
Output will not be created.
[/pre]

There -is- still good news. If you use ODS HTML or ODS MSOFFICE2K, you can create multiple, separate HTML files, each with a graph on/in it. Then, using a different approach, you can LINK the files together. Microsoft will allow each separate HTML file to be a worksheet, however, ALL the files have to live in a subdirectory. So let's say that you want to call your workbook BigRept.html and it will be stored in c:\temp:

c:\temp\BigRept.html

you will need a subdirectory called:
c:\temp\BigRept_files

in the BigRept_files directory, you will have your ODS HTML files AND the graph images files and maybe a CSS file. Let's say the files are stored like this:
c:\temp\BigRept_files\chart1.html
c:\temp\BigRept_files\chart2.html
c:\temp\BigRept_files\chart3.html

Then, you also need an "organizing" file...let's call that file orglist.xml and it, too is in the subdirectory: c:\temp\BigRept_files\orglist.xml
and it looks like this:
[pre]
<xml xmlns:o="urn:schemas-microsoft-com:office:office">
<o:MainFile href="BigRept.html"/>
<o:File href="chart1.html"/>
<o:File href="chart2.html"/>
<o:File href="chart3.html"/>
<o:File href="Orglist.xml"/>
</xml>[/pre]

Now, back to your "top" file c:\temp\BigRept.html (or you could call it BigRept.xls), it has to contain ALL the related file names (like those shown in Orglist.xml), but in a different format:[pre]

xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">









[/pre]

Now, if you call this file BigRept.xls and IF you have your subdirectory created and place all the related file in the subdirectory, then when you double click on BigRept.xls, then Excel should open all the related files together.

If you call the file BigRept.html, then you have to Right Mouse click and either do an Open with Excel or you have to open Excel and manually open the HTML file. Either way, you will get a multi sheet workbook -including- graphics.

This approach is outined in this R&D presentation:
http://support.sas.com/rnd/base/topics/excel/multisheet_excel_post.ppt

So, the good news is that you can do what you want, it just takes a bit more work than using Spreadsheet Markup Language.

cynthia
deleted_user
Not applicable
Cynthia,

How about using ODS tagsets.excelxp to do a graph after the data is already in excel? My request can be satisfied very easily. Either A) use ODS to create/overwrite certain sheets in an excel workbook having one page be the the presentation page that links to the data sheets or B) use said tagset to create a graph using some other method after the data is in excel such as tagattr?

It's a serious problem for my firm b/c everyone is starting to move to R since it's graphing capabilities are easier to use. I'm a SAS guy, but I can't argue with them on that one.

Thx.
Cynthia_sas
SAS Super FREQ
Hi:
TAGSETS.EXCELXP has to abide by Microsoft's rules. Once the file is created by ODS TAGSETS.EXCELXP -- it is an ASCII text, Excel 2003 Spreadsheet Markup Language XML file. Excel might allow you to make a graph in that file -- using Excel's drop-down menus. However, if you then try to save the file as Excel 2003 XML, you will get the following message -in Excel-. In fact, if I just open Excel to a blank workbook (without having SAS involved) and then I type some data and build a graph, if I then save the file as Excel 2003 XML, I get the same message -- from Excel:

Book1.xls may contain features that are not compatible with XML Spreadsheet 2003. do you want to keep the workbook in this format?
Yes------------No------------Help

and then if you click Help, you get to Microsoft Help, which says that:

This XML Spreadsheet 2003 file format (.xml) does not retain the following features:

--Auditing tracer arrows
--Chart and other graphic objects
--Chart sheets, macro sheets, dialog sheets
--Custom views
--Data consolidation references
--Drawing object layers
--Outlining and grouping features
--Password-protected worksheet data
--Scenarios
--User-defined function categories
--VBA projects


So even if ODS -could- send some kind of commands to Excel to make a graph when the file is opened, the Excel XML format just does NOT have any commands in XML related to building graphs. But, ODS can only send XML that's been defined (such as XML for changing orientation, column-width, print headers, etc), so since Microsoft did not even build graphing capabilities into Excel 2003 XML, there's nothing that SAS can do on that front.

A lot of my students report that they use Excel macros or VB Scripts to save the ODS-generated XML to binary Excel format. In that case, they can use any Excel commands or macros or scripts to insert Excel-based graphics into the file.

However, to specifically address your questions/suggestions:
A) ODS cannot overwrite a single sheet in a workbook -- when ODS creates a file, it is creating an ASCII text file (either HTML or XML or CSV) that Excel knows how to open and render -- ODS cannot write to an existing Excel workbook.

B) the ODS tagset MUST conform to a specification -- an HTML tagset must conform to the HTML 4.0 or HTML 3.2 or Microsoft HTML specification -- in that specification, you point to an IMAGE with an &LT;IMG&GT; tag. ODS does that.

With the TAGSETS.EXCELXP tagset, Microsoft did not define a way, in the specification, to create a graph using the XML tags. After the ODS output is rendered in Excel, SAS is out of the picture -- it is no longer able to "send" anything to Excel. Technically, the output that you create with ODS is not in native Excel format until you SAVE the file to a native Excel format. The only way to create true, binay Excel files in native Excel format is to use PROC EXPORT or the SAS Libname engine for Excel.

The other way to send data from SAS to Excel is to use DDE or ODBC or OLE-DB. None of these methods, however, use ODS. ODS creates an ASCII text file -- either ODS CSV or ODS HTML or ODS MSOFFICE2K or ODS TAGSETS.EXCELXP -- they all create ASCII text files in one form or another that Excel knows how to open and render.

In fact, when you create an ASCII text file and the ASCII file is RENDERED in Excel -- it is rendered for you, using Excel as the "viewer", but then Excel will try to save the file to the same format it opened, unless you specifically RESAVE the ASCII file as one of the Excel formats (either .xlsx or .xls) which represents a native Excel format.

Note that, the example below (run in SAS 9.2) does create an HTML file with an image that can be opened in Excel. Each HTML file that you create would represent one worksheet in one workbook. If you wanted to link multiple HTML files together into a multi-sheet workbook, then you would use the techniques that I outlined in the posting above. (Note that the file extension of .XLS is being used to force the output to open in Excel when double-clicked. Otherwise, with an extension of .HTML, the output would open in a browser when double-clicked. ODS, in the code below is creating an ASCII text HTML file that can be opened and rendered in Excel.)

cynthia
[pre]
ods html path='c:\temp' (url=none)
file='Excel_with_graph.xls' style=sasweb;

goptions device=jpeg hsize=12in vsize=7in;

proc gchart data=sashelp.shoes;
title 'Average Sales of Shoe Products';
vbar product / sumvar=sales type=mean;
run;
quit;

ods html close;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 6391 views
  • 0 likes
  • 3 in conversation