DATA Step, Macro, Functions and more

PROC REPORT: Create heading only when no data present

Accepted Solution Solved
Reply
Highlighted
Occasional Contributor
Posts: 12
Accepted Solution

PROC REPORT: Create heading only when no data present

[ Edited ]

how can i get only headers without any data when i write a proc report.

 

This will be help for me when there is no data in the dataset 

 

 

 

Thanks 

Vamsi.


Accepted Solutions
Solution
‎10-28-2016 09:21 AM
Respected Advisor
Posts: 3,786

Re: PROC REPORT: Create heading only when no data present

[ Edited ]
data class;
   stop;
   set sashelp.class;
   run;

*if class has 0 obs add 1 with missing values for all variables;
*if class has obs this does nothing;
data class;
   if eof then output;
   stop;
   modify class end=eof;
   run;

options missing=' ';
proc report data=class missing;
   columns _all_;
   define _all_ / display;
   define name / order;
   compute before name;
      holdname=name;
      endcomp;
   compute after;
      if missing(holdname) then l=40; else l=0;
      msg = 'No data to report';
      line msg $varying40. l;
      endcomp;
   run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,695

Re: Report doubt

You can't directly.  Output is only generated when there is data.  Now you could do one of two things:

Insert a record into the empty dataset which states "No data to report" or something similar - this is what I tend to do, seen it many times across my field, as its clear then that there is no data to report.

The other alternative is to put some default value/text into the dataset, and when you report it, set the font color to be the same as the background color, hence hiding the text, you will just see an empty report - however not recommended as this could also occur if page breaks are messed up or some other problem happens, so its not clear to the reviewer.

Super User
Posts: 9,865

Re: Report doubt

[ Edited ]

The only thing I can think is making a table contain these variables name.

 

proc transpose data=sashelp.class(obs=0) out=class;
 var _all_;
run;
proc transpose data=class out=want(drop=_name_ _label_);
 var _name_;
run;
proc report data=want noheader nowd;run;
Solution
‎10-28-2016 09:21 AM
Respected Advisor
Posts: 3,786

Re: PROC REPORT: Create heading only when no data present

[ Edited ]
data class;
   stop;
   set sashelp.class;
   run;

*if class has 0 obs add 1 with missing values for all variables;
*if class has obs this does nothing;
data class;
   if eof then output;
   stop;
   modify class end=eof;
   run;

options missing=' ';
proc report data=class missing;
   columns _all_;
   define _all_ / display;
   define name / order;
   compute before name;
      holdname=name;
      endcomp;
   compute after;
      if missing(holdname) then l=40; else l=0;
      msg = 'No data to report';
      line msg $varying40. l;
      endcomp;
   run;
Valued Guide
Posts: 632

Re: PROC REPORT: Create heading only when no data present

@data_null__I especially like your use of the $VARYING. format to essentially conditionally execute the LINE statement.

Respected Advisor
Posts: 3,786

Re: PROC REPORT: Create heading only when no data present

@ArtC I think it is worth mentioning this Usage Note: http://support.sas.com/kb/37/763.html

Valued Guide
Posts: 632

Re: PROC REPORT: Create heading only when no data present

[ Edited ]

Thank you @data_null__I do so love to learn, of course remembering is even better (and all too often the real challenge) Smiley Happy .

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 1347 views
  • 2 likes
  • 5 in conversation