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

 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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Hi , May i ask why not proc sql? Thanks

echoli
Obsidian | Level 7

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

Reeza
Super User

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.

 

ballardw
Super User

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

 

 

echoli
Obsidian | Level 7

Hi ballardw,

 

I've marked the observations as red color.

 

Thanks,

C

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1596 views
  • 0 likes
  • 4 in conversation