What is your concern with using NLOBSF?
Years ago I was inspired by this paper by Jack Hamilton:
https://support.sas.com/resources/papers/proceedings/proceedings/sugi26/p095-26.pdf
And wrote a obscount macro, the core of which is to use NLOBS if SAS knows the number of records and there is no WHERE options, else use NLOBSF:
%if %sysfunc(attrn(&idnum, ANOBS)) and %sysfunc(attrn(&idnum, WHSTMT))=0 %then %do;
%*If sas knows number of obs, and there is no where statement, get nlobs;
%let nlobs = %sysfunc(attrn(&idnum,nlobs)); %*get number of obs;
%end;
%else %if %sysfunc(attrn(&idnum, ANOBS))=0
or (1<=%sysfunc(attrn(&idnum, WHSTMT)) and %sysfunc(attrn(&idnum, WHSTMT)) <=3) %then %do;
%*If sas doesnt know number of obs, or there is a where statement, get nlobsf (this iterates through dataset);
%let nlobs = %sysfunc(attrn(&idnum,nlobsf)); %*get number of obs;
%end;
Yes, DOSUBL is slow compared to most other functions, because it's doing a LOT of work (creating and destroying the side session to run execute the code).
... View more