Skip to content
9to5sas
  • Index
  • Glossary
Facebook Twitter Instagram Email RSS

  • Start Here
  • Base SAS
  • Advanced SASExpand
    • SAS Macros
    • PROC SQL
  • SAS/STATSExpand
    • SAS Analytics
    • Statistics
  • SAS Programs
9to5sas

9to5sas » SAS PROGRAMS » Determine the log of a variable in SAS

Determine the log of a variable in SAS

BySubhro Posted onMarch 31, 2021August 29, 2021 Last Updated:August 29, 2021
0 Comments

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.

Log

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;

Output:

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;
	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:

Determine the log of a variable in SAS

 

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

JOIN OUR COMMUNITY OF SAS Programmers!

Check your inbox or spam folder to confirm your subscription.

Subhro

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.

Facebook Twitter Linkedin

Post navigation

Previous Previous
Append records to an existing file in SAS
NextContinue
Confidence Interval Calculator

SAS Tips in your inbox

Subscribe to 9to5sas for timely SAS tips and news delivered each month.
Learn about the latest articles, and code samples to keep your SAS skills fresh!

Your subscription is successful!

Recent Posts

  • Concatenate strings in SAS: The CAT Functions Demystified
  • 5 Techniques for Quickly Removing Leading Zeros in SAS
  • Troubleshoot Your Proc SQL Code Like a Pro with These 7 Automatic Macro Variables
  • 7 PROC SQL Options You Should Use to Debug Queries
  • How To Use The SAS Proc SQL Order By Statement?
9to5sas
  • Privacy Policy
  • Disclaimer
  • About
  • Contact
Facebook Twitter Instagram RSS Email Pinterest

Copyright © 2023 9TO5SAS, All rights reserved.

Scroll to top
  • 9to5sas Blueprint
  • About
  • About
  • Acceptable use policy
  • calculator
  • Confirm email
  • Contact
  • Contact
  • Cookie Policy
  • DISCLAIMER
  • Getting Started with SAS
  • Glossary
  • Index
  • Post #13801
  • Privacy Policy
  • Privacy policy
  • SAS Programs
  • Styles
  • Subscription confirmed
  • Terms and conditions
  • Thank You