BookmarkSubscribeRSS Feed
ballardw
Super User

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.

 

s_lassen
Meteorite | Level 14

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.

SuryaKiran
Meteorite | Level 14

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);

 

Thanks,
Suryakiran

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 3310 views
  • 5 likes
  • 9 in conversation