BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
always-good
Obsidian | Level 7

Hello!

How to transform data through the log transformation to ensure a normal distribution for the somatic cells count variable, please?

is there any test to test the normality of the data before?

Finally, is there a procedure or other way to do the log transformation?

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
whymath
Lapis Lazuli | Level 10

To transform a variable to its logarithmic form, you just need to apply "log()" function, this function returns the natural (base e) logarithm. You can also use "log2()" (base 2) and "log10()" (base 10).

data _null_;
  x=10;
  y1=log(x);
  y2=log2(x);
  y3=log10(x);
  put y1=/ y2=/ y3=;
run;

y1=2.302585093
y2=3.3219280949
y3=1

 

To test the normality of data, you can use "proc univariate" with a "normal" option.

proc univariate data=sashelp.class normal qqplot;
  var height;
run;

The result window will show you test result like this:

1.png

You can also use qqplot statement in this procedure, to get a Q-Q plot of analysis variable.

View solution in original post

2 REPLIES 2
whymath
Lapis Lazuli | Level 10

To transform a variable to its logarithmic form, you just need to apply "log()" function, this function returns the natural (base e) logarithm. You can also use "log2()" (base 2) and "log10()" (base 10).

data _null_;
  x=10;
  y1=log(x);
  y2=log2(x);
  y3=log10(x);
  put y1=/ y2=/ y3=;
run;

y1=2.302585093
y2=3.3219280949
y3=1

 

To test the normality of data, you can use "proc univariate" with a "normal" option.

proc univariate data=sashelp.class normal qqplot;
  var height;
run;

The result window will show you test result like this:

1.png

You can also use qqplot statement in this procedure, to get a Q-Q plot of analysis variable.

Ksharp
Super User
For single variable to test the normality try NORMATEST option:

proc univariate data=sashelp.heart normaltest;
var weight;
run;

For multiple variables to test normality try @Rick_SAS 's blog:
https://blogs.sas.com/content/iml/2012/03/02/testing-data-for-multivariate-normality.html

For transforming data to conform normal distribution ,try Box-Cox transformation:
https://blogs.sas.com/content/iml/2022/08/22/box-cox-transform.html
https://blogs.sas.com/content/iml/2022/08/17/box-cox-regression.html

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 889 views
  • 2 likes
  • 3 in conversation