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

后端 未结 7 1228
慢半拍i
慢半拍i 2020-11-29 04:47

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 d

7条回答
  •  清酒与你
    2020-11-29 05:33

    The trick is producing an output even when the dataset is empty.

    data CountObs;
    
        i=1;
        set Dataset_to_Evaluate point=i nobs=j; * 'point' avoids review of full dataset*;
        No_of_obs=j;
        output;  * Produces a value before "stop" interrupts processing *;
        stop;   * Needed whenever 'point' is used *;
        keep No_of_obs;
    run;
    
    proc print data=CountObs;
    run;
    

    The above code is the simplest way I've found to produce the number of observations even when the dataset is empty. I've heard NOBS can be tricky, but the above can work for simple applications.

提交回复
热议问题