DATA Step, Macro, Functions and more

find min value in a column within different groups

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 84
Accepted Solution

find min value in a column within different groups

[ Edited ]

 Hi All,

 

How to output the min value in a column within different groups? I want to use data step, not proc sql.

 

I have a data like below, I want output min pValue in each group. The observations in red color are what I want. Any idea? THanks,

Obs

group

Sex

pValue

1

(2) Young

Female

0.0023

2

(2) Young

Male

0.0536

3

(3) Child

Female

0.0814

4

(3) Child

Male

0.3191

5

(4) Teen

Female

0.0561

6

(4) Teen

Male

0.0979


Accepted Solutions
Solution
‎05-08-2017 09:45 AM
Super User
Posts: 19,832

Re: find min value in a column within different groups

Sort it and use FIRST.

 

 

proc sort data=have;
by myByGroup pvalue;
run;

data want;
set have;
by myByGroup ;

if first.myByGroup;
run;

 

The SQL solution is one step.

 

View solution in original post


All Replies
PROC Star
Posts: 283

Re: find min value in a column within different groups

Hi , May i ask why not proc sql? Thanks

Frequent Contributor
Posts: 84

Re: find min value in a column within different groups

Posted in reply to novinosrin

Oh, nothing, I just want to know how to do it in data step.Smiley Very Happy

Solution
‎05-08-2017 09:45 AM
Super User
Posts: 19,832

Re: find min value in a column within different groups

Sort it and use FIRST.

 

 

proc sort data=have;
by myByGroup pvalue;
run;

data want;
set have;
by myByGroup ;

if first.myByGroup;
run;

 

The SQL solution is one step.

 

Super User
Posts: 11,343

Re: find min value in a column within different groups

Please show exactly what you expect the output for that example data to look like.

 

 

Frequent Contributor
Posts: 84

Re: find min value in a column within different groups

Hi ballardw,

 

I've marked the observations as red color.

 

Thanks,

C

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 117 views
  • 0 likes
  • 4 in conversation