4 C
London
Friday, December 20, 2024
HomeSASData Munging in SASHow to Use the MIN Function in SAS (With Examples)

How to Use the MIN Function in SAS (With Examples)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

You can use the MIN function in SAS to find the smallest value in a list of values.

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

Method 1: Find Minimum Value of One Column in Dataset

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

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

proc sql;
    select var2, min(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 print data=my_data;

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

Example 1: Find Minimum Value of One Column in Dataset

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

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

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

This represents the minimum value in the points column.

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

The following code shows how to calculate the minimum value in the points column, grouped by the team column in the dataset:

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

From the output we can see:

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

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

Additional Resources

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

How to Calculate Z-Scores in SAS
How to Use Proc Summary in SAS
How to Calculate Mean, Median, & Mode in SAS

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories