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 |
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.
Hi , May i ask why not proc sql? Thanks
Oh, nothing, I just want to know how to do it in data step.
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.
Please show exactly what you expect the output for that example data to look like.
Hi ballardw,
I've marked the observations as red color.
Thanks,
C
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.