BookmarkSubscribeRSS Feed
Ken_oy
Fluorite | Level 6
Hi

Can we calculate the maximum value of a variable, in the data statement?
I don't want to use Proc means, since I need to merge this maximum value back to my dataset.

e.g. in the following dataset, do we have any function like

max_v2 = max( v2 ) , ??

-----------------------------
id v2

1 2
2 4
3 5
4 3
5 4
6 5
7 6
8 3

--------------------------------------

Thanks!!

Ken
3 REPLIES 3
DanielSantos
Barite | Level 11
It can be done with datastep (by retaining the maximum value for example), but it is easier and clearer to be done through proc sql or even proc summary/means.

Give a look at the documentation of the RETAIN statement:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
deleted_user
Not applicable
Ken,

You don't say what you want to do with this maximum, so it is a bit hard to advise you. For example, you could figure out the maximum in a data step, but it wouldn't be known for sure until you get to the last observation. You could make an initial pass through the data file using the POINT option. Or, you could also use SQL:

proc sql noprint;
create table NEW as
select *, max(v2) as max_v2
from ORIGINAL
;
quit;
Ken_oy
Fluorite | Level 6
Thanks Kmg!!

This is exactly what I want!!

Thanks again! Problem FIXED!!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1345 views
  • 0 likes
  • 3 in conversation