Determine the log of a variable in SAS
March 31, 2021
1 min
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`]("https"://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lefunctionsref&docsetTarget=p0l7s11dwvzfq5n1wnw997dye8fx.htm&locale=en#p12c30o3nnxlu7n186c3ytfju9bg) 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.```sasdata Ex2;x=constant('E');y=log(constant('E'));put x= y=;run;```**"Output":**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 baseYou 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;```**"Output":**<p id="duNRTzn"></p>export const _frontmatter = {"title":"Determine the log of a variable in SAS","slug":"determine-the-log-of-a-variable-in-sas","date":"2021-03-31T10:48:57","modified":"2021-08-29T11:23:13","excerpt":"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.","author":"Subhro","authorSlug":"subhroster","categories":["SAS PROGRAMS"],"tags":[],"wordpressId":8696,"wordpressLink":"https://www.9to5sas.com/determine-the-log-of-a-variable-in-sas/","featuredImage":8704,"type":"post"}