The SAS Output Delivery System and reporting techniques

ExcelXP - Create an empty tab when dataset is empty

Reply
Contributor
Posts: 53

ExcelXP - Create an empty tab when dataset is empty

Hi all,

I'm using the excelXP tagset to create an Excel workbook with 2 tabs. Sometimes one of the datasets is empty and the tab is not produced at all. In the case of an empty dataset, I'd still like to produce the tab with just a header row so the user knows the report was run but found no records. Suggestions?
Valued Guide
Posts: 2,177

Re: ExcelXP - Create an empty tab when dataset is empty

modify that empty dataset to have just one "missing" row, with something like this
- assuming the data set is named in &dataset and it is the kind of data set that will have a value for NOBS[pre]
data _null_ ;
if not nobs then
call execute( 'data &dataset; output ; set &dataset ; run ; ' ) ;
stop;
set &dataset nobs=nobs ;
run ;[/pre]seems to work for me

peterC
Contributor
Posts: 53

Re: ExcelXP - Create an empty tab when dataset is empty

That worked perfectly! Thanks much!
Respected Advisor
Posts: 3,799

Re: ExcelXP - Create an empty tab when dataset is empty

This method that I thought I learned from you seems more concise. Plus it does not rely on NOBS.

data &dataset;
if _n_ eq 1 and eof then output;
stop;
modify &dataset end=eof;
run;
Valued Guide
Posts: 2,177

Re: ExcelXP - Create an empty tab when dataset is empty

Posted in reply to data_null__
glad someone remembers ;-)
Ask a Question
Discussion stats
  • 4 replies
  • 219 views
  • 0 likes
  • 3 in conversation