Finding the number of observations in SAS dataset
There are a number of ways of finding out the number of observations in a SAS data set and, while they are documented in a number of different places, I have decided to collect them together in one place. At the very least, it means that I can find them again. First up is the most basic and least efficient method: read the whole data set and increment a counter a pick up its last value. The END option allows you to find the last value of count without recourse to FIRST.x/LAST.x logic. data _null_ ; set test end=eof; count+1; if eof then call symput( "nobs" ,count); run; The next option is a more succinct SQL variation on the same idea. The colon prefix denotes a macro variable whose value is to be assigned in the SELECT statement; there should be no surprise as to what the COUNT(*) does… proc sql noprint; select count(*) into :nobs from test; quit; Continuing the SQL theme, accessing the dictionary tables is another route to the same end and has the advantage of need...