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!!

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!

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