06-20-2018 07:28 AM - edited 06-20-2018 07:35 AM
The following contains a solution to the same question:
Edit: You can assign the macro variable a value of 0 before trying to find the actual value.
06-20-2018 07:49 AM
%let count = 0; proc sql noprint; select nobs into :count trimmed from sashelp.vtable where libname = "LIB" and memname = "DATASET" ; quit;
Note that library and dataset-name have to be all upcase.
06-20-2018 08:19 AM
Why do you need it in a macro variable? The reason I ask is is because there are better methods to run code if observations exist, and in most scenarios code will run even if there are no observations. So there is rarely or never a need to create a macro variable for this, especially since the data is already present in sashelp.vtable, e.g.
data _null_; set sashelp.vtable (where=(libname="<yourlib>" and memname="<yourds>")); call symputx('num_obs',nobs); run; %put &num_obs.;
06-20-2018 08:47 AM
For the discussion @Amir references I'd write the macro a bit differently as below:
%macro get_table_size(inset,macvar); %global &macvar; data _null_; call symput("&macvar",put(nobs,f15. -l)); stop; set &inset nobs=nobs; run; %mend; %get_table_size(sashelp.class,n_obs) %put &=n_obs; data test; length var 8; stop; run; %get_table_size(test,n_obs) %put &=n_obs;