DATA Step, Macro, Functions and more

Report request obs from dataset

Reply
N/A
Posts: 0

Report request obs from dataset

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
Valued Guide
Posts: 2,177

Re: Report request obs from dataset

Posted in reply to deleted_user
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 .
Super User
Posts: 10,018

Re: Report request obs from dataset

Posted in reply to deleted_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
Valued Guide
Posts: 2,177

Re: Report request obs from dataset

> 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
Super User
Posts: 10,018

Re: Report request obs from dataset

OK.
Peter , Your right. Assuming the dataset OP has is not large.


Regards
Ksharp Message was edited by: Ksharp
Ask a Question
Discussion stats
  • 4 replies
  • 130 views
  • 0 likes
  • 3 in conversation