BookmarkSubscribeRSS Feed
deleted_user
Not applicable
If a dataset contain 200 observations, how to report obs no 29, 46, 89 and 185
using base sas and proc sql. Thanks in advance
4 REPLIES 4
Peter_C
Rhodochrosite | Level 12
if you have nothing more to use as a filter than the obs no, then look at the point= option odf the SET statement. This is not available to proc sql .
Ksharp
Super User
[pre]
data want;
set sashelp.class;
if _n_ in ( 2,4,8:12);
run;
[/pre]


Which extract 2th,4th, and 8 - 12 obs

Ksharp Message was edited by: Ksharp
Peter_C
Rhodochrosite | Level 12
> 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
Ksharp
Super User
OK.
Peter , Your right. Assuming the dataset OP has is not large.


Regards
Ksharp Message was edited by: Ksharp

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 1005 views
  • 0 likes
  • 3 in conversation