How can I use the MAX function in SAS and what are some examples? 2

How can I use the MAX function in SAS and what are some examples?

The MAX function in SAS is a statistical function used to find the maximum value in a given dataset or a list of specified values. It can be used in various data analysis and reporting tasks to identify the highest value in a set of data points. To use the MAX function, the syntax is “MAX (variable1, variable2, …)” where the variables represent the values for which the maximum value is to be determined. This function can also be combined with other functions and logical operators to create more complex expressions. For example, the MAX function can be used to find the highest sales figure in a sales report or to identify the maximum temperature recorded in a weather dataset. In summary, the MAX function is a useful tool in SAS that allows for easy identification of the highest value in a dataset, making it a valuable feature for data analysis and reporting.

Use the MAX Function in SAS (With Examples)


You can use the MAX function in SAS to find the largest value in a list of values.

Here are the two most common ways to use this function:

Method 1: Find Max Value of One Column in Dataset

proc sql;
    select max(var1)
    from my_data;
quit;

Method 2: Find Max Value of One Column Grouped by Another Column in Dataset

proc sql;
    select var2, max(var1)
    from my_data;
    group by var2;
quit;

The following examples show how to use each method with the following dataset in SAS:

/*create dataset*/
data my_data;
    input team $ points;
    datalines;
A 12
A 14
A 19
A 23
A 20
A 11
A 14
B 20
B 21
B 29
B 14
B 19
B 17
B 30
;
run;

/*view dataset*/
proc printdata=my_data;

Note: The MAX function automatically ignores missing values when calculating the max value of a list.

Example 1: Find Max Value of One Column in Dataset

The following code shows how to calculate the max value in the points column of the dataset:

/*calculate max value of points*/
proc sql;
    select max(points)
    from my_data;
quit;

We can see that proc sql returns a table with a value of 30.

This represents the max value in the points column.

Example 2: Find Max Value of One Column Grouped by Another Column

/*calculate max value of points grouped by team*/
proc sql;
    select team, max(points)
    from my_data;
    group by team;
quit;

From the output we can see:

  • The max points value for team A is 11.
  • The max points value for team B is 14.

Note: You can find the complete documentation for the MAX function in SAS .

The following tutorials explain how to perform other common tasks in SAS:

Cite this article

stats writer (2024). How can I use the MAX function in SAS and what are some examples?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-the-max-function-in-sas-and-what-are-some-examples/

stats writer. "How can I use the MAX function in SAS and what are some examples?." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-the-max-function-in-sas-and-what-are-some-examples/.

stats writer. "How can I use the MAX function in SAS and what are some examples?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-the-max-function-in-sas-and-what-are-some-examples/.

stats writer (2024) 'How can I use the MAX function in SAS and what are some examples?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-the-max-function-in-sas-and-what-are-some-examples/.

[1] stats writer, "How can I use the MAX function in SAS and what are some examples?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can I use the MAX function in SAS and what are some examples?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top