Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select specific rows by row number in sas

Tags:

sas

I am new to SAS I have SAS data like (It does not contain Obs column)

Obs    ID    Name    Score1    Score2    Score3

1     101               90        95        98
2     203               78        77        75
3     223               88        67        75
4     280               68        87        75
.
.
.
.
100   468               78        77        75

I want data having row number 2 6 8 10 34. Output should look like

Obs    ID    Name    Score1    Score2    Score3

1     203               78        77        75
2     227               88        67        75
3     280               68        87        75
.
.
.

Thanks in advance.

like image 500
Sangram Avatar asked Dec 20 '22 06:12

Sangram


1 Answers

The other answer is ok for small tables, but if you are working with a very large table it's inefficient as it reads every row in the table to see whether it has the right row number. Here's a more direct approach:

data example;
    do i = 2, 6, 8, 10;
        set sashelp.class point = i;
        output;
    end;
    stop;
run;

This picks out just the rows you actually want and doesn't read all the others.

like image 183
user667489 Avatar answered Dec 30 '22 03:12

user667489