Hi,
I have this dataset, where Col A could have a repeating value (e.g. 990).
I would like the dataset to look like this (select for highest value of '990' so =3)
I tried this code that I found on SAS communities (and a few other variations of it):
proc means data=sashelp;
class record_id ColA;
var ColB;
output out=want max(ColB)=ColB;
run;
I ended up getting this output where instead of sas giving me the highest value, I got the average of the values of 990.
How do I fix it so that SAS gives me only the highest value for a repeating observation instead of the average?
Thanks in advance!
Hello,
This code should do the trick, but records are not returned in same order.
proc sort data=work.have out=work.want0;
by record_id ColA descending ColB;
run;
data work.want1;
set work.want0;
by record_id ColA descending ColB;
if first.ColA then output;
run;
/* end of program */
Koen
That's easy
, but can you provide us with your (sample) data by means of a data step with datalines (cards) statement?
We cannot code against a picture.
When pasting your SAS code (the requested data step), use the running man icon in the toolbar.
Thanks,
Koen
Hello,
This code should do the trick, but records are not returned in same order.
proc sort data=work.have out=work.want0;
by record_id ColA descending ColB;
run;
data work.want1;
set work.want0;
by record_id ColA descending ColB;
if first.ColA then output;
run;
/* end of program */
Koen
Its fine that you have marked the answer as correct, as I'm sure it is correct.
But, there's no reason that PROC MEANS won't give you the correct maximum either ... and so again I conclude that there's something going in your specific data that you haven't told us about (and maybe it is something you aren't even aware of), and again I suspect you have formatted the variable somehow.
For anyone else reading along, PROC MEANS ought to do the job properly.
@Zozo1998 wrote:
Hi,
I have this dataset, where Col A could have a repeating value (e.g. 990).
I would like the dataset to look like this (select for highest value of '990' so =3)
I tried this code that I found on SAS communities (and a few other variations of it):
proc means data=sashelp;
class record_id ColA;
var ColB;
output out=want max(ColB)=ColB;
run;
I ended up getting this output where instead of sas giving me the highest value, I got the average of the values of 990.
How do I fix it so that SAS gives me only the highest value for a repeating observation instead of the average?
Thanks in advance!
What is the format on variable ColB, according to PROC CONTENTS?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.