An Idea Exchange for SAS software and services

by PROC Star
on ‎04-07-2014 12:32 PM


I think you are mistaken about what the macro processor is doing.

In the SAS language, a dot is used to represent a missing value stored in a numeric variable.

In the macro language, a dot does not represent a missing value.  It's just a dot.  The macro language does not know about data set variables.  It only processes text.

When you code: %if 1 > %then do;  the macro languages compares the 1 on the left side of the operator to the null string on the right side.  There are definitely cases where it is useful to compare some value to a null string.  As a point of style, some people would code this as: %if 1 > %str() %then do;    This is a little more explicit that the right hand side is a null string.

If you test:  %if . > %then %do you will find it evaluates to 1 (TRUE).  Because SAS compared a dot to a null string.  If it had implicitly inserted a dot on the right side, it would evaluate to FALSE:

%macro CheckCondition(condition);
  %put The condition &condition evaluates to %eval(&condition);
%mend CheckCondition;

17   %CheckCondition(1> )
The condition 1> evaluates to 1
18   %CheckCondition(.> )
The condition .> evaluates to 1
19   %CheckCondition(.>.)
The condition .>. evaluates to 0

Use of null values in the macro language is common.  e.g. %let x= ;   or keyword parameters that have a default value of null.  I think it would be a mistake to make this an error.

by Valued Guide
on ‎04-08-2014 12:09 AM

A nice paper on the macro language's comparison of a text value to a null value can be found at (Chung and King, 2009):

by New Contributor ArietenCate
on ‎04-08-2014 07:36 AM

Thanks. I am getting to understand this better now.  The dot was how it was formulated by the local SAS Supporter.


Idea Statuses
Top Liked Authors