BookmarkSubscribeRSS Feed
SeaMoon_168
Obsidian | Level 7

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 340 views
  • 5 likes
  • 4 in conversation