BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ShaheenRanalvi
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

4 REPLIES 4
art297
Opal | Level 21

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

ShaheenRanalvi
Calcite | Level 5

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

Haikuo
Onyx | Level 15

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.

ShaheenRanalvi
Calcite | Level 5

Thank you !!

Regards,

Shaheen

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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