BookmarkSubscribeRSS Feed
SeaMoon_168
Quartz | Level 8

I would use the code to read row 100 to row 200 from a large dataset named "LargeData" below:

data subset;
set LargeData (firstobs=100 obs=200);
run;

Any other better options? Many thanks!

4 REPLIES 4
mkeintz
PROC Star

There are no better options, because the system will use the dataset pagesize to determine which page (think which physical block of disk storage) has obs 100.  And from there on it's sequential access through obs 200.     You would get almost as fast if firstobs=100100 obs=100200, because SAS doesn't read through the preceding disk blocks to get to the one of interest.

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SASKiwi
PROC Star

In my experience FIRSTOBS and OBS are a very efficient way of pulling a small sample of rows from a large dataset so I don't see any need to find a 'better' way as long as it runs reliably and efficiently for your use case.

Ksharp
Super User
/*If your data engine allow randomly to access*/
data want;
do _n_=100 to 200;
 set sashelp.heart point=_n_;
 output;
end;
stop;
run; 
mkeintz
PROC Star

The "downside" of POINT= is that SAS has to recalculate the page containing the desired obs for each iteration of the DO loop, unlike sequential access.  This probably isn't too bad because that calculation is pretty quick, and the identified page for each iteration is likely to be cached from the prior iteration.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 4 replies
  • 1417 views
  • 5 likes
  • 4 in conversation