Get where condition into the output

This post was kindly contributed by Ken's SAS tricks - go there to comment and to read the full post.

The where statement is a powerful and useful tool for subsetting on the fly.  But one problem with it is that the output doesn’t show the conditioning.  This is a little macro I wrote to correct this problem:

%macro where(wherest, titleline);
where &wherest;
title&titleline “where %str(&wherest)”;
%mend where;

If you use %where(condition, n); in place of where condition; the condition is both implemented and will appear in the output as the nth title line.  This takes advantage of the fact that the title statements just need to appear before the proc is run.

Note that for reasons I haven’t bothered to discover, you need to use the mnemonic “eq” and not the assignment “=” in your where statements for this to work.

This post was kindly contributed by Ken's SAS tricks - go there to comment and to read the full post.