# SAS Data Transformation: Using Log Transformation in SAS

**sas data transformation, sas log function, sas natural log, log transformation in sas, log transformation in sas**

**SAS Data Transformation, Introduction**

Using SAS for data transformation is not difficult. Performing the log transformation in SAS refers to calculating the ** natural** log. To perform the calculation requires the use of the log function. This function works the same as any other SAS function. Before considering the details, remember that a log transformation can follow an input, set or by statement.

**Syntax for SAS LOG Function**

To perform a log transformation in SAS requires one argument as input into the log function. Most commonly, the argument supplied is the name of the variable.

You can also specify a *numeric constant or expression, aside from a variable. *

**LOG(argument)**

Second, the argument must be a *positive* numeric constant, variable or expression. In this example below, we are specifying a numeric constant.

**xvar=log(5.0)**

Finally, an example where we use a numeric variable as the argument. In this scenario, we are taking a log of peoples weight. Weight is the numeric variable and our argument.

**xvar=log(weight)**

You could probably guess how to do a log base 10 transformation.

**xvar=log10(weight)**

### What Do You Do With Negative Data Values?

This is where LOG1PX function can be really helpful. Let’s look at the syntax below.

**LOG1PX(x)**

Let’s add some detail in terms of what it does for us. LOG1PX returns the log of 1 + the argument (x).

**LOG1PX(x) = log(1 + x)**

So, let’s understand the utility of it.

First, using LOG1PX when our x is closer to 0 will lead this function to give us a more accurate result than if we used just log(x). If you need to prove this to yourself, feel free to try it now and print out the output/results.

Second, since you can’t use negative values with log(x), the 1 + x of the LOG1PX function will allow you to do the transformation. So, this is certainly one useful way of dealing with negative values when you want to perform a transformation.

### Reversing/Converting Back to Original

To reverse or convert back to the original value is also quite straightforward.

To reverse the natural log requires the use of the exponential function. The argument you supply the exponential function will be the variable that has stored the natural log transformation.

revert_back = exp(argument)

### Conclusion

As you can see, performing a log transformation in SAS is not difficult. Nevertheless, if you have any questions, please ask in the comments below. I would be more than happy to help you.

Written by Ermin

You may be interested in this article:

## 2 Responses

How to convert it back to normal value ?

Anshul,

exp(x) would be the reverse of the natural log. This is the exponential function. So just pass in the variable that was storing the natural log result.