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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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