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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1667 views
  • 0 likes
  • 3 in conversation