How to detect how many observations in a dataset (or if it is empty), in SAS?

sas
mj023119 picture mj023119 · Apr 14, 2011 · Viewed 47.8k times · Source

I wonder if there is a way of detecting whether a data set is empty, i.e. it has no observations. Or in another saying, how to get the number of observations in a specific data set.

So that I can write an If statement to set some conditions.

Thanks.

Answer

Laurent de Walick picture Laurent de Walick · Apr 14, 2011

It's easy with PROC SQL. Do a count and put the results in a macro variable.

proc sql noprint;
 select count(*) into :observations from library.dataset;
quit;