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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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