# Calculate Logs to Base Other Than e or 10

## Problem

How can I calculate the logarithm of a variable for a base other than e (2.718) or 10?

## Resolving The Problem

You can use the LN function and the base of interest in a compute statement to compute the logarithm of a variable for that base. Suppose you have a variable named VARX and want to compute its log for base 2 and store that value in LOG2X. The following statement would work on any version of SPSS.

COMPUTE LOG2X = LN(VARX)/LN(2) .

The reasoning for this method is as follows. The statement that Y is the base 2 logarithm for X can be expressed as
2**Y = X (2**Y is 2 to the power of Y)

Take the natural log of both sides of the equation.
Y * ln(2) = ln(X).

Solve for Y by dividing both sides by ln(2).
Y = ln(X)/ln(2).

The logarithm for any other base would be calculated in a similar manner. For the log for base 5:

COMPUTE LOG5X = LN(VARX)/LN(5)

## Related Information

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

14465

Modified date:
16 April 2020

swg21476045