Subsetting data

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

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
Respected Advisor
Posts: 3,124

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.

View solution in original post


All Replies
PROC Star
Posts: 7,356

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
Respected Advisor
Posts: 3,124

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 259 views
  • 1 like
  • 3 in conversation