Hi all,
I need use this formular in SAS, but since am getting wrong results, please can anyone see if I interpretted anything wrong
NewVar= 0,56x√(TJC28)+0,28x√(SJC28)+0,70xlognat(BSG)+0,014xGG
I did interprete it like this in my SAS-Code:
NewVar=(0.56*sqrt(TJC28))+(0.28*sqrt(SJC28))+(0.70*log(BSG))+(0.014*GG);
Am not sure if natural log is calculated this way in SAS
Please, I will appreciate any help
The formula seems correct. Can you break down the formula components? Is this an Excel formula? Maybe some decimal digitss are hidden?
how do you mean, to break the formula components. The given names are the variable names
Are the values of these the same on both sides:
(0.56*sqrt(TJC28))
(0.28*sqrt(SJC28))
(0.70*log(BSG))
(0.014*GG)
With which system did you compare the result you get in SAS? And how did you code the formula in that reference system?
Run this code:
data _null_;
le = log(10);
put le=;
run;
and see if your reference system comes up with the same value for an argument of 10.
(BTW, the value is of course correct).
Why wouldn't you have negative values? With small values for BSG, the log will be negative:
data have;
input tjc28 sjc28 bsg gg;
datalines;
.03 .03 .01 1
;
data check;
set have;
NewVar =
0.56 * sqrt(TJC28)
+
0.28 * sqrt(SJC28)
+
0.70 * log(BSG)
+
0.014 * GG
;
run;
(a bsg value of zero would result in negative infinity)
From the SAS documentation:
LOG Function
Returns the natural (base e) logarithm.
This seems to answer your question.
Hello @Anita_n
In SAS the function log(a) is actually natural log i.e. ln. The function log10(a) refers to log to the base 10.
Have a look at the following code to understand the use of the functions.
Please note i have assigned some numerical values to your variables to explain the concept.
data _NULL_;
TJC28=100;
SJC28=250;
BSG=500;
GG=1000;
NewVar_e=(0.56*sqrt(TJC28))+(0.28*sqrt(SJC28))+(0.70*log(BSG))+(0.014*GG);
NewVar_10=(0.56*sqrt(TJC28))+(0.28*sqrt(SJC28))+(0.70*log10(BSG))+(0.014*GG);
put NewVar_e=;
put NewVar_10=;
run;
In the log we see
Provide an full example of "wrong result", this means the values of all variables, the result you get and the value you compare it to that tells you the SAS result is "wrong".
Thanks @ballardw for reading the post commenting that everything is wrong.
Please help me understand where I am wrong.
Learning is a life long exercise and we learn many things in course of time.
My post showed the following
1. Log() function gives natural log (ln)
2. log10() gives log to the base 10
3.I took an example using the formula in the first post by @Anita_n
The idea was to show the difference in the output of the two functions.
Lastly there are many different ways of doing the same thing,
and many different ways of communicating the same thing.
The more importing thing is to appreciate that somebody responded to a question.
@Sajid01 wrote:
Thanks @ballardw for reading the post commenting that everything is wrong.
Please help me understand where I am wrong.
Learning is a life long exercise and we learn many things in course of time.
My post showed the following
1. Log() function gives natural log (ln)
2. log10() gives log to the base 10
3.I took an example using the formula in the first post by @Anita_n
The idea was to show the difference in the output of the two functions.Lastly there are many different ways of doing the same thing,
and many different ways of communicating the same thing.
The more importing thing is to appreciate that somebody responded to a question.
I was hoping to see the actual values of some variables and the results that @Anita_n is using and seeing.
In Excel natural log is ln. it's different than log (which is base 10)
log(10) ln(10)
10 1.0000000 2.3025851
Hello all,
thanks for your responses and the ideas. Here are some data samples am using and the corresponding results I got in SAS compared to excel:
TJC28 | SJC28 | CRP | GG | SAS: NewVar | Excel Results |
3 | 3 | 0,09 | 18 | 0,02136075 | 0,97489243 |
0 | 0 | 0,7 | 20 | 0,03032754 | 0,17156863 |
0 | 0 | 0,6 | 30 | 0,06242206 | 0,26470588 |
0 | 0 | 1 | 5 | 0,07 | 0,07 |
0 | 0 | 0,02 | 0 | -2,7384161 | -1,189279 |
0 | 0 | 0,02 | 10 | -2,5984161 | -1,049279 |
0 | 0 | 0,023 | 5 | -2,5705827 | -1,0767905 |
0 | 0 | 0,031 | 5 | -2,3616377 | -0,9860468 |
This is the formula: 0,56x√(TJC28)+0,28x√(SJC28)+0,70xlognat(CRP)+0,014xGG
and this was how I interpretted it in SAS
NewVar=(0.56*sqrt(TJC28))+(0.28*sqrt(SJC28))+(0.70*log(CRP))+(0.014*GG);
You can see that the results I get from SAS is different from what I get from SAS. My caculator gives the same results like excel. Thanks for any solution
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.