SAS: LOG Functions

Deepanshu Bhalla Add Comment

In this article we will show how to use log functions in SAS, along with examples.

LOG Functions in SAS

  • newvar = log(var1);: Calculates the natural logarithm (base e) of the "var1" variable.
  • newvar = log10(var1);: Calculates the logarithm base 10 of the "var1" variable.
  • newvar = log2(var1);: Calculates the logarithm base 2 of the "var1" variable.
  • newvar = log10(var1)/log10(4);: Calculates the logarithm base 4 of the "var1" variable.
Sample Dataset

Let's create a sample SAS dataset for the examples in this article.

data have;
input salary;
cards;
1000
1230
2211
2520
;
run;
data want;
set have;
salary_log = log(salary);
salary_log10 = log10(salary);
salary_log2 = log2(salary);
run;
LOG Functions in SAS

data want;: This line defines a new SAS dataset named "want" that will be created to store the transformed data. set have;: This line instructs SAS to read data from an existing dataset named "have." The "have" dataset is the source dataset from which the "salary" variable will be obtained.

How to calculate LOG in any base in SAS

In the code below, we are calculating the log in base 4. To compute the logarithm in base 4, we have divided the logarithm of the salary in base 10 by the logarithm of 4 in base 10.

data want;
set have;
salary_log4 = log10(salary)/log10(4);
run;
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

Post Comment 0 Response to "SAS: LOG Functions"
Next → ← Prev