Help using Base SAS procedures

maximum value in data set

Posts: 30

maximum value in data set

What are the possible methods for picking the maximum value from a variable in data set using data step (not using proc sql) .Can we do it with Max function . can anyone plz explain with ex?If not with MAX function any other method using data step .

Thanks in advance for your replies
Not applicable
Posts: 0

Re: maximum value in data set


data maximums;
*retain a variable which holds the maximum value found so far;
retain maximum;
set input_dataset;
*if you find a higher value then update the maximum;
if variable>maximum then maximum=variable;

Your last observation will have the maxmum value in it.

There are many other ways but that's a pretty good simple starting point.

Peter Message was edited by: pznew
Super User
Posts: 5,878

Re: maximum value in data set

I find questions of the type "I know how to do it in SQL but how do I do it in the data step" a bit strange. I use to ask myself the opposite question - how can I do it in SQL instead? I prefer SQL if performance and coding complexity is the same (or better in SQL). There are in my opinion two advantages by using SQL in such cases:
- Non SAS experts can read and understand the code.
- Running the code against non SAS data can exploit the possibilities of using the benefits in implicit SQL pass-thru, which in turn can increase performance.

Data never sleeps
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation