A minor tweak (simple, but improves efficiency), or a major one (more complex but a lot more efficiency in the case of large data sets).
Minor (don't bother reading the last 30% of the file):
data want;
set have nobs=_nobs_; if _n_ > 0.45*_nobs_;
if _n_ > 0.70 * _nobs_ then stop;
run;
The above actually reads (and throws away) the first unwanted 45% of the file, but at least stops once the 70% obs has been reached.
Major tweak. But if your file is big, you might want to avoid reading the first 45%, just to throw it away. You can use the data set parameter FIRSTOBS to tell sas to skip the first 45% (and the OBS parameter to tell it to stop at 70%). To do that ask dictionary.tables for the number of observations, and use macro expressions to calculate FIRSTOBS and OBS:
proc sql; select nobs into :nrecs from dictionary.tables where libname='WORK' and memname='HAVE';
quit;
%let fobs=%sysfunc(floor(%sysevalf(0.45*&nrecs))); %let obs=%sysfunc(ceil(%sysevalf(0.7*&nrecs)));
data want;
set have (firstobs = &fobs obs=&ob );
run;
regards,
Mark
... View more