2
votes

In trying to make my code more readable, I face the following situation.

Consider a data step in which you want to select only observations which have a value for variable. It seems there are two ways to do this using a WHERE statement: express the variable alone or use the MISSING function.

For example,

Case 1. Where VARIABLE

data where_var;
  set sashelp.electric;
  where AllPower;
run;

Case 2. Where not missing(VARIABLE)

data where_not_missing;
  set sashelp.electric;
  where not missing(AllPower);
run;

These produce the same result. However, I'm unsure whether this is necessarily the case.

  • Are these functionally equivalent?
  • Is Case 1 merely syntactic sugar for Case 2?
  • Are there instances when they will produce different results?
2

2 Answers

5
votes

In SAS, any numeric value other than 0 or missing is true. See https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm for more info.

That means that your Case 1 and Case 2 are not 100% equivalent. If AllPower = 0, the result will be different.

0
votes

If you are trying to determine if AllPower has a value then only Case 2 will work.

Case 1 is selecting records where AllPower is non-zero. Zero is a value and is not the same as missing.