In SAS, there is no power() function. To perform exponentiation as well as find the roots of numbers in a SAS data step, you can use **.

data have;
     a = 10;
     b = a**2;
     put b=;
run;

/* Output */
b=100

SAS allow us to perform many different kinds of calculations in our code easily.

One such calculation is exponentiation of numbers to square, cube, take a number to the 5th, etc, or find roots of a number with fractional powers.

We can use the SAS **() operator to do exponentiation.

Let’s say we have the following code which creates a SAS dataset with some numbers.

data data;
	input num;
	datalines;
4
16
5
-2
3
-10
;
run;

Below are some examples of how to use ** in a data step.

data data_with_powers;
	set data;
        square = num**2;
        cube = num**3;
        square_root = num**(1/2);
run;

This results in the following SAS dataset:


        num    square   cube     square_root
1         4        16     64               2
2        16       256   4096               4
3         5        25    125    2.2360679775
4        -2         4     -8               .
5         3         9     27    1.7320508076
6       -10       100  -1000               .

How to Square a Number in a SAS Data Step

If you want to square a number in a SAS data step, you can use ** and put a ‘2’ after the **.

Below is an example of how you can square a number in SAS.

data have;
     a = 10;
     b = a**2;
     put b=;
run;

/* Output */
b=100

How to Find the Square Root of a Number in a SAS Data Step

If you want to find the square root of a number in a SAS data step, you can use ** and put a ‘1/2’ after the **.

Below is an example of how you can find the square root of a number in SAS.

data have;
     a = 100;
     b = a**(1/2);
     put b=;
run;

/* Output */
b=10

Hopefully this article has been useful for you to learn how to use ** in SAS to perform exponentiation and find roots in a SAS data step.

Categorized in:

SAS,

Last Update: February 26, 2024