%macro nextNB(ds);
%local dsid nv rc;
%let dsid = %sysfunc(open(&ds));
%let nv = %sysfunc(smallest(2, &dsid));
%let rc =%sysfunc(close(&dsid));
&nv
%mend nextNB;
%put %nextNB(WORK.TEST);
&dsid returns a dataset with values 5, 7 and 9. How do I change my macro function such that it returns the 2nd smallest value 7?