• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS min() Function – Find Minimum Value Across Columns in Data Step

SAS min() Function – Find Minimum Value Across Columns in Data Step

October 2, 2022 Leave a Comment

The SAS min() function allows you to find the minimum value across columns and returns the smallest number in a data step.

data example;
 a = min(1,4,7);
 put a;
 b = min(1,.,-1);
 put b;
run;

/* Log Output */
1
-1

When working with different data in programming, the ability to be able to easily find summary statistics of pieces of your data is valuable.

One such case is if you want to find the minimum number of multiple values.

In a SAS data step, you can find the minimum number of multiple numbers or multiple columns with the min() function.

Below shows you some simple examples of using min() in a SAS data step.

data example;
 a = min(1,4,7);
 put a;
 b = min(1,.,-1);
 put b;
run;

/* Log Output */
1
-1

Find Minimum Across Columns in Data Step with min()

You can use min() to create a new column which has the minimum value across a number of columns in a SAS dataset.

For example, let’s say you had some variables and wanted to find the minimum of each observation for those variables.

To do this, you can use min() and pass the column names as the arguments.

Below shows you how to create a new column which is the minimum value across the columns A, B and C in a data step.

data example;
input A B C;
datalines;
5 1 2
4 2 3
3 3 4
2 4 5
1 5 6
;
run;

data example_with_min;
    set example;
    M = min(A,B,C);
run;

/* Output */
A B C M
5 1 2 1
4 2 3 2
3 3 4 3
2 4 5 2
1 5 6 1

Treatment of Missing Values with SAS min() Function in Data Steps

If your data has missing values, then you have to be aware of how min() calculates the minimum if you have values which are missing that are passed to min().

In general, missing values will be ignored by min().

This is shown below, where I’ve included one missing value in the call to min().

data example;
 a = min(1,.,-1);
 put a;
run;

/* Log Output */
-1

However, if all values are missing, then min() will return a missing value.

data example;
 a = min(.,.,.);
 put a;
run;

/* Log Output */
.

Find Minimum of Entire Column in SAS with PROC MEANS

If you want to find the minimum of an entire column, then you should use PROC MEANS.

In SAS, PROC MEANS is a procedure which allows you to create summaries of your data and allows you to calculate things like the sum, mean, min, max, etc. of a variable.

You can find the minimum of an entire column by specifying the MIN option with PROC MEANS.

Below shows you how to find the minimum of an entire column using the SAS PROC MEANS procedure.

data example;
input group $ value;
datalines;
A 1
A 2
A 3
B 4
B 5
B 6
C 7
C 8
;
run;

proc means data=example min;
    variable value;
run;

proc means min

Find Maximum Across Columns in Data Step with max() Function

If you’d instead like to find the maximum of values in a SAS data step, you can use the SAS max() function.

max() works in the same way as min() and allows you to find the maximum across multiple columns in a SAS data set.

Below shows some simple examples of how you can use max() in a SAS data step.

data example;
 a = max(1,4,7);
 put a;
 b = max(1,.,-1);
 put b;
run;

/* Log Output */
7
1

Hopefully this article has been useful for you to learn how to use the SAS min() function in your SAS programs.

Other Articles You'll Also Like:

  • 1.  SAS Percent Format – Formatting Number as Percent in SAS Dataset
  • 2.  Change Length of Character Variable in SAS Dataset
  • 3.  countw SAS – Count Number of Words in a String
  • 4.  SAS sum() Function – Find Sum Across Columns in Data Step
  • 5.  SAS prxmatch – Find Pattern in String Using Regex (Regular Expression)
  • 6.  =">SAS Greater Than or Equal to with GE or >=
  • 7.  SAS max() Function – Find Maximum Value Across Columns in Data Step
  • 8.  Round Number to Nearest Integer in SAS
  • 9.  catx SAS – Concatenate String Variables with Delimiter in SAS Data Step
  • 10.  SAS floor – Round Down to Floor of Number in a SAS Data Step

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy

x