Determine the log of a variable in SAS

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;
	put x=;

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;
	put x= y=;


Determine the log of a variable in SAS

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;

	do i=1 to 10;

		/* Y equals the LOG, base B, of X*/


Determine the log of a variable in SAS


Every week we'll send you SAS tips and in-depth tutorials


Subhro Kar is an Analyst with over five years of experience. As a programmer specializing in SAS (Statistical Analysis System), Subhro also offers tutorials and guides on how to approach the coding language. His website, 9to5sas, offers students and new programmers useful easy-to-grasp resources to help them understand the fundamentals of SAS. Through this website, he shares his passion for programming while giving back to up-and-coming programmers in the field. Subhro’s mission is to offer quality tips, tricks, and lessons that give SAS beginners the skills they need to succeed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap