As a new SAS user, the NOBS parameter may be all you need. However, as your coding skills increase, you may find yourself in situations where this is not appropriate. The NOBS parameter in the SET statement may not work in all cases. The return value will be the number of physical observations in the dataset, including any observations that might have been removed in place. It may also not work with certain views (especially views related to external databases).
The βsafestβ way to find the number of recovered cases in a dataset or view is to use PROC SQL and actually count them by placing the result in a macro variable. For example, suppose you have a data object named HAVE:
proc sql noprint; select count(*) into : nobs from WORK.HAVE; quit; %put 'Obs in data set:' &nobs;
Note that this works if HAVE is a dataset or view.
Alternatively, if you are an object of only a dataset, you can use the SAS TABLES Dictionary view to return the NLOBS attribute, which has a number of βlogicalβ observations (that is, accounting for all deleted rows):
proc sql noprint; select nlobs into : nobs from dictionary.tables where libname='WORK' and memname='HAVE'; quit; %put 'Obs in data set:' &nobs;
This will certainly be more effective if your SAS dataset is very large. I often wondered why SAS does not make this NLOBS value available as an option in the SET statement, but I'm sure there are reasons.
PROC SQL, views, macro variables and in-place remote observations may be completely new to you right now, but as you progress with SAS training, you will definitely start using them.
Bellevuebob
source share