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: 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
  • 4 replies
  • 740 views
  • 0 likes
  • 4 in conversation