
Rick A. answered 04/04/19
Experienced SAS Professional
Here's one solution. It keeps NOBS local but NUM_OF_OBSERVATIONS must be global to be of any use in subsequent steps of the program.
%macro nobs(library_name, table_name);
%local nobs;
data _null_;
set &library_name..&table_name(obs=1) nobs=tot_obs; /* note: NOBS= is a SAS option and isn't related to the macro variable nobs of same name */
/*return nobs macro variable; &nobs*/
call symputx('nobs', tot_obs);
run;
%let num_of_observations=&nobs.;
%mend nobs;
%nobs(work, patients); /* get num_of_observations */