Solved
Contributor
Posts: 21

# Subsetting data

How to subset data based on Proc Univariate's result?For eg: if i want to see the whole row and all the variables connected with an observation having highest and lowest value?

Accepted Solutions
Solution
‎08-08-2012 08:15 AM
Posts: 3,167

## Re: Subsetting data

First sort descending, then choose the first 5 obs.

proc sort data=have;

by descending value ;

run;

data want;

do i=1 to 5;

set have point=i;

output;

end;

stop;

run;

Haikuo: update from ascending (my brainfart) to descending.

All Replies
PROC Star
Posts: 8,165

## Re: Subsetting data

You could always open the dataset in a datastep, limiting the records included by using an if or where statement.

Contributor
Posts: 21

## Re: Subsetting data

Thank you for the reply Arthur.

I have a cancer data.I used proc univariate to find out the maximum 5 values of the type of cancer.

Extreme Observations

-----Lowest----        -----Highest-----

Value      Obs           Value      Obs

6790        6          572626       24

7544       12         2106499       26

12864       21         2477847       22

14098       11         5017159        1

14355       13         6081291        2

Now,how do i subset data which will contain only the records having observation number 1 , 2,24,26 and 22 (highest)?There is no variable that is unique for these observations(like no ssn no.etc)

Using if or where but how?

is there any provision that we can use_n_ = ?

Kindly help.

Regards,

Shaheen

Solution
‎08-08-2012 08:15 AM
Posts: 3,167

## Re: Subsetting data

First sort descending, then choose the first 5 obs.

proc sort data=have;

by descending value ;

run;

data want;

do i=1 to 5;

set have point=i;

output;

end;

stop;

run;

Haikuo: update from ascending (my brainfart) to descending.

Contributor
Posts: 21

## Re: Subsetting data

Thank you !!

Regards,

Shaheen

🔒 This topic is solved and locked.