BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Kathryn_SAS
SAS Employee
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)
deleted_user
Not applicable
Wow ... thanks ... it's not something I would have easily guessed at or likely worked my way through.


Thanks !


Serge
vevans
Calcite | Level 5

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 2431 views
  • 0 likes
  • 3 in conversation