ODS and Base Reporting

Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!
BookmarkSubscribeRSS Feed
SB_145
Fluorite | Level 6

 I am looking for a way to export only the header of a dataset to Excel. No matter whether I tried, from starting with an empty dataset to using a filter right before the export, SAS doesn't export the tab that contains a header only.

Any suggestions would be highly appreciated.
Thank you!

6 REPLIES 6
SB_145
Fluorite | Level 6
I know it's ironic that the topic about exporting an Excel file with a header only has only a header (it was unintentional--SAS reps., we need an edit button).

Now the actual issue: I am looking for a way to export only the header of a dataset to Excel. No matter whether I tried, from starting with an empty dataset to using a filter right before the export, SAS doesn't export the tab that contains a header only.

Any suggestions would be highly appreciated.
Thank you!
Tom
Super User Tom
Super User

Do you have to use ODS?  This works:

libname out xlsx 'myfile.xlsx';
data out.class;
  set sashelp.class (obs=0);
run;
SB_145
Fluorite | Level 6
Hi Tom, Thank you for your suggestions. Unfortunately it doesn't work. I'm working on a Unix server, though I doubt this is the cause (never had problems creating actual Excel files) 1) The result of your export code is a file with the extension $$1. 2) When I try to export my own empty dataset, I do obtain an Excel file; however when I try to open it, I get a message that the file is corrupted. 3) If I try to export my data to a file with multiple tabs, the tab that should contain only with the header is not created at all. For what's worth, my header has column names down the lines of '20-DEC-2019 01'n. Could this be the cause of the problem (it's not a problem when I export at least the first observation)? Thank you again.
Tom
Super User Tom
Super User

Sounds like you tried to read the XLSX file before SAS had finished creating it.  If you open the XLSX with a libname statement you need to clear the libref before it closes the file and saves it.

libname out xlsx 'myfile.xlsx';
data out.class ;
  set sashelp.class ;
  where age=0;
run;
data out.cars;
  set sashelp.cars (obs=5);
run;
libname out clear ;
SB_145
Fluorite | Level 6

I still get a $$1 file. I even erased everything in the destination folder, closed Excel, and changed the server from which I run the code. Same exact result. Using a WHERE statement vs. an OBS statement made no difference either. 

 

Thank you.

Tom
Super User Tom
Super User

Click on the vertical dot-dot-dot next the message to see the edit message menu item.

image.png

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2053 views
  • 2 likes
  • 2 in conversation