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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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