BookmarkSubscribeRSS Feed
keen_sas
Quartz | Level 8
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
2 REPLIES 2
deleted_user
Not applicable
Hi,

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;
run;

Your last observation will have the maxmum value in it.

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

Cheers
Peter Message was edited by: pznew
LinusH
Tourmaline | Level 20
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.

Regards,
Linus
Data never sleeps

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