# Determine the log of a variable in SAS1 min read

0 0 vote
Article Rating ## Determine the log of a variable in any base

There are multiple logarithmic functions available to determine the log of a variable in SAS. The most used log functions are the natural and common log functions.

The natural LOG function returns the natural (base e) logarithm.

``````data Ex1;
x=log(1);
put x=;
run;``````

In Example 1, with the input of 1, SAS returns the expected value of 0 and using Euler’s Number approximation of 2.71828, the result y is very close to 1.

You can use the CONSTANT function that will return the value of a mathematical constant. For Euler’s Number, the notation is ‘E’. From reviewing the log using CONSTANT(‘E’), the expected value of 1 is returned.

``````data Ex2;
x=constant('E');
y=log(constant('E'));
put x= y=;
run;`````` For the common log, the SAS function is LOG10. The LOG2 function returns the binary logarithm, or base 2.

## Program to Determine the log of a variable in any base

You can compute the log of a variable in any base using the LOG function and the property.

```logB(X)=log(X) / log10(B)

```

X is the variable whose log will be determined. B is the base of the log that will be determined and Y is the log, base b, of x.

``````data ex1;
b=6;

do i=1 to 10;
x=int(ranuni(12345)*100);

/* Y equals the LOG, base B, of X*/
y=LOG10(x)/LOG10(b);
output;
end;
run;`````` 0 0 vote
Article Rating
Subscribe
Notify of This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top