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

Hi, 

I have this dataset, where Col A could have a repeating value (e.g. 990). 

Screen Shot 2022-01-11 at 12.46.46 PM.png

I would like the dataset to look like this (select for highest value of '990' so =3) 

Screen Shot 2022-01-11 at 12.53.05 PM.png

 

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.

Screen Shot 2022-01-11 at 12.51.23 PM.png

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! 

 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

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

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ

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

sbxkoenk
SAS Super FREQ

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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
PaigeMiller
Diamond | Level 26

@Zozo1998 wrote:

Hi, 

I have this dataset, where Col A could have a repeating value (e.g. 990). 

Screen Shot 2022-01-11 at 12.46.46 PM.png

I would like the dataset to look like this (select for highest value of '990' so =3) 

Screen Shot 2022-01-11 at 12.53.05 PM.png

 

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.

Screen Shot 2022-01-11 at 12.51.23 PM.png

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?

--
Paige Miller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 744 views
  • 2 likes
  • 3 in conversation