As you've discovered, you can't put a parameter in to restrict the count of observations in DUPS10 (or generally for any output dataset). Of course you could run a second data step, as @SuryaKiran demonstrated. That technique will give the first SORTED 10.
There is a way to do the complete task in a single data step, with the usage of two hash objects: one (named SRTED below) will yield sorted have, with no duplicate keys, and the second (NAM) will provide the exact count of duplicates you want:
data have;
set sashelp.class;
ran=ranuni(012498105);
output;
ran=ranuni(049810444);
output;
ran=ranuni(0259866);
output;
run;
proc sort data=have out=have (drop=ran);
by ran;
run;
data duplicates (drop=_:);
set have;
if _n_=1 then do;
declare hash srted(dataset:'have',ordered:'A');
srted.definekey('name');
srted.definedata(all:'Y');
srted.definedone();
srted.output(dataset:'have_sorted');
declare hash nam();
nam.definekey('name');
nam.definedone();
end;
if nam.find()^=0 then nam.add();
else do;
output;
_ndupes+1;
if _ndupes>=10 then stop;
end;
run;
The resulting data set HAVE_SORTED will have only one record per name - because that is a default property of sas hash objects. It will have the record containing first instance of each sort key - exactly as the NODUPKEY option in PROC SORT.
The NAM hash is used to trace whether an incoming record (from the original HAVE dataset) has been encountered before. If it has, then is it a duplicate - to be output to DUPLICATES and counted in _NDUPES. Note these duplicates will not be in sorted order, since they are based on processing the original unsorted HAVE.
... View more