If you want to specify specific sequences of observations here is one way:
data junk1 ; set have(firstobs=1 obs=250 ); run; data junk2 ; set have(firstobs=251 obs=500); run;
but the question does beg for an answer of what gets done with an apparently arbitrary number of records.
With an arbitrary number of records, the best way may be to find the number of records first, e.g.:
data _null_; call symputx('nobs',nobs);
stop; set have nobs=nobs;
run; data want1; set have(obs=%eval(&nobs/4)); run; data want2; set have(firstobs=%eval(&nobs/4+1) obs=%eval(&nobs/2)); run; data want3; set have(firstobs=%eval(&nobs/2+1) obs=%eval(3*&nobs/4)); run; data want4; set have(firstobs=%eval(3*&nobs/4+1)); run;
As shown, it needs a little familiarity with SAS macro language. Which is hard to avoid if you want to do this kind of "advanced" stuff.
Hope this macro program will be helpful.
%MACRO test(lib=,ds=);
proc sql;
select count(*) INTO: nobs
from &lib..&ds. ;
Quit;
%put &nobs;
%do i=0 %to &nobs. %by %SYSFUNC(CEIL(&nobs./4)) ;
data out&i;
set &lib..&ds.(firstobs=%EVAL(&i+1) obs=%EVAL((&nobs./4)+&i) ) ;
run;
%end;
%mend;
%test(lib=sashelp,ds=class);
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.