Custom Functions

Besides providing a collection of built-in functions, Sass lets you write your own functions to reuse logic in your code. A Sass @function is similar to a @mixin, because they both extract repeating patterns from your code. However, instead of outputting style declarations or rule sets like mixins do, a function outputs a single value; a function does NOT return any CSS.

You could write Sass functions to handle certain calculations you repeat in your CSS.
SCSS

@function divide($a, $b) {
  @return ($a / $b);
}
.test {
  line-height: divide(32px, 16px);
}

CSS

.test {
  line-height: 2;
}

Example: pixels to percentage.

$max-width: 1000px; 

@function px-to-pc($target, $context: $max-width) {
  @return ($target / $context) * 100%;
}

.test {
  width: px-to-pc(400px, 1200px);
}

$context: $max-width A parameter given a default value is called an optional parameter.
You can omit the argument for it when calling the function.