BookmarkSubscribeRSS Feed
Lawongd
Calcite | Level 5

I will like to write a code for values of x = (-0.1, 0.0, 0.1)

 write code to calculate L (x ; mu = 0, sigma = 1)

 

In R code (L <-function(x, u=0, s2=1)(sqrt(2*pi*s2))^-1*exp(-(x-u)^2/(2*s2))
x<-c(-0.1,0.0, 0.1)
L(-0.1)

L(0.0)

L(0.1)

 

Thanks 

4 REPLIES 4
Lawongd
Calcite | Level 5

Thanks to everyone who helped me have a better understanding of how this works. 

Ksharp
Super User

Try PDF() function. And post it at IML forum , calling @Rick_SAS 

Rick_SAS
SAS Super FREQ

 

As KSharp points out, your function is the PDF of the normal distribution. The PDF function is one of several built-in functions for working with probability distributions, so you can just call the PDF function directly. You can call it from the DATA step or from PROC IML:

 

 

data Want;
do x = -0.1 to 0.1 by 0.1;
   y = pdf("Normal", x); /* default is u=0, s=1 */
   output;
end;
run;
proc print; run;

proc iml;
x = {-0.1, 0, 0.1};
y = pdf("Normal", x); /* default is u=0, s=1 */
print x y;

If the goal of the exercise is to define a SAS/IML function module. see the article "Everything you wanted to know about writing SAS/IML modules." which discusses how to define functions and how to define default arguments.

 

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 858 views
  • 0 likes
  • 4 in conversation