The SAS Output Delivery System and reporting techniques

Newbi wants Title even if there is no output

Reply
N/A
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 = '';
run;

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?



Serge
SAS Employee
Posts: 22

Re: Newbi wants Title even if there is no output

Posted in reply to deleted_user
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?
A:
Use the following program to print information to the Output window if a data set is empty:

data one;
x=1;
run;
data two;
stop;
run;

/** 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";
run;
%end;
%else %do;
data _null_;
title;
file print;
put _page_;
put "Data set &dsn is empty.";
run;
%end;

%mend;
%drive(one)
%drive(two)
N/A
Posts: 0

Re: Newbi wants Title even if there is no output

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


Thanks !


Serge
N/A
Posts: 1

Re: Newbi wants Title even if there is no output

Posted in reply to deleted_user

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,

Vince

Ask a Question
Discussion stats
  • 3 replies
  • 434 views
  • 0 likes
  • 3 in conversation