The SAS Output Delivery System and reporting techniques

Newbi wants Title even if there is no output

Posts: 0

Newbi wants Title even if there is no output

Hi Folks,

Been learning a lot about SAS over the last month. I have figure out how to do a few things like outputting stuff to HTML via ODS (even getting what I want!).

One problem I am having is, I'd like a title from a proc to appear even if the proc produces zippo.
For instance, I have no records with unknown gender.
so this procedure:
proc freq data =
jomama.test formchar(1,2,7)='|-+' order=data;
table id*sex;
where sex = '';

Results in no output, but I'd like something like a title like 'Id*sex (blank)' to appear - even if there is no data to go with it.

I tried attaching a title command to the proc and I presume it works, but still get no title, am assuming that it would print, if there were blanks in the gender.

Any ideas on what I could do to make that appear?

SAS Employee
Posts: 22

Re: Newbi wants Title even if there is no output

See the following FAQ:

FAQ # 1753
Q: Is there a method for printing information to the Output window even when a data set is empty?
Use the following program to print information to the Output window if a data set is empty:

data one;
data two;

/** This macro prints the data set if it contains observations and prints
a message if the data set has zero observations. **/

options mprint;
%macro drive(dsn);

/** Opens the data set to be read **/
%let dsid=%sysfunc(open(&dsn));

/** Determine the number of observations in the dataset **/
%let cnt=%sysfunc(attrn(&dsid,nobs));

/** Close the data set **/
%let rc=%sysfunc(close(&dsid));

/** if data set is not empty, issue a PROC PRINT **/
%if &cnt ne 0 %then %do;
proc print data=&dsn;
title "This is data from data set &dsn";
%else %do;
data _null_;
file print;
put _page_;
put "Data set &dsn is empty.";

Posts: 0

Re: Newbi wants Title even if there is no output

Wow ... thanks ... it's not something I would have easily guessed at or likely worked my way through.

Thanks !

Posts: 1

Re: Newbi wants Title even if there is no output

How would you implement this same MACRO however if DATA ONE and DATA TWO had different titles (i.e. say there were 75 different Data steps and each one had differing titles). How would you incorporate that into the macro to output the title if there was data as well as output titles for no data (which is already shown here)

Best regards,


Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation