Created
May 25, 2021 06:56
-
-
Save rudvfaden/5dba82df3d59464661c7232c2e5d1996 to your computer and use it in GitHub Desktop.
Tries to count nobs by metadata, else default to recusion count.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro nobs(data=_last_); | |
%local dsid anobs whstmt counted rc; | |
%let DSID = %sysfunc(open(&DATA., IS)); | |
%if &DSID = 0 %then %do; | |
%put %sysfunc(sysmsg()); | |
%let counted = .; | |
%goto mexit; | |
%end; | |
%else %do; | |
%let anobs = %sysfunc(attrn(&DSID, ANOBS)); | |
%end; | |
%if &anobs=1 %then | |
%let counted = %sysfunc(attrn(&DSID, NLOBS)); | |
%else %do; | |
%put INFO: Observations in "&DATA." must be counted by iteration.; | |
%let counted = 0; | |
%do %while (%sysfunc(fetch(&DSID)) = 0); | |
%let counted = %eval(&counted. + 1); | |
%end; | |
%end; | |
%let rc = %sysfunc(close(&DSID)); | |
%MEXIT: | |
&COUNTED. | |
%mend nobs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment