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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 580 views
  • 2 likes
  • 3 in conversation