> data want;
> set sashelp.class;
> if _n_ in ( 2,4,8:12);
> run;
>
>
> Which extract 2th,4th, and 8 - 12 obs
>
> Ksharp
ok, but
if the table from which certain rows are read is large, your method will read the whole table, and the alternative I suggested (POINT= option on SET statement) reads only requested rows when used like
data want ;
do pointer = 2,4,8 to 12, 1000 ;
set your.table point= pointer ;
from_row=pointer ; *the variable "pointer" cannot be kept because it is named by a statement option!;
if _error_ then _error_ =0 ;
else output ;
end ;
stop;
run ;
the test for _error_ catches the accident of pointing to rows which are not there because they are already marked as deleted or pointing to a row beyond the end of file.
Replacing "your.table" above with sashelp.class, here is the SASlog[pre]633 data want ;
634 do pointer = 2,4,8 to 12, 1000 ;
635 set sashelp.class point= pointer ;
636 point=pointer ; *the variable "pointer" cannot be kept because it is named by a statement option!;
637 if _error_ then _error_ =0 ;
638 else output ;
639 end ;
640 stop;
641 run ;
NOTE: The data set WORK.WANT has 7 observations and 6 variables.
NOTE: DATA statement used[/pre]
and a listing[pre]point selections 12:08 Thursday, February 23, 2011 1
Obs Name Sex Age Height Weight point
1 Alice F 13 56.5 84.0 2
2 Carol F 14 62.8 102.5 4
3 Janet F 15 62.5 112.5 8
4 Jeffrey M 13 62.5 84.0 9
5 John M 12 59.0 99.5 10
6 Joyce F 11 51.3 50.5 11
7 Judy F 14 64.3 90.0 12