Problem with RAND code


Fortran must die
I am running this code (which should work and is pretty basic).

%let N=10000;
Data normal (keep=x);
Call streaminit(4321);
mu=0; sigma=1;
Do i=1 to &N;
x = rand(‘NORMAL’,mu, sigma);

And I get this baffling error where the rand function is:

ERROR 386-185: Expecting an arithmetic expression.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

I have gone over this forever and can't find any problem with the code.
That's strange, I ran the code and didn't get any errors. My only thought is that based on the error messages, there might be a typo in your code in the editor.
Last edited:


Fortran must die
Using the double quotations worked. What is wacky is that when I ran other distributions such as geometric with "" I got errors that went away when I ran ''. And the SAS site shows '' not "".

I suspect that running this inside enterprise guide might be the issue. Although it is not supposed to influence regular code done in windows.



Ambassador to the humans
Are you just copying/pasting code from the SAS pages? It doesn't always copy over perfectly so you need to be careful. And if part of the purpose is to learn how to code these simulations one habit you should get into is physically typing the code yourself. You have to think about it slightly more when you type it. And straight up copying/pasting code can lead to errors like this if you aren't careful. But mainly I suggest typing it out because it's better for you and you'll learn more.


Fortran must die
No actually I am working through "Simulating DATA with SAS" by Richard Wicklin. He has code for different distributions which I am typing into code windows (he has discussions of the distributions as well that is interesting and not covered in SAS). For example sas does not let you change the scale paramater sigma for exponential distributions with the RAND function. Wicklin created a way to do it himself (it is not clear to me what the default sigma is for SAS's random selection from an exponential distributions as their web page does not cover this. My guess is they chose 1 because that is the sigma value for a standardized normal distribution, but that is a wild guess).

Thanks dason. My goal is not only to learn how to code this, but to learn more about the distributions. For example I don't really know, but aim to find out, what having a different scale distribution means substantively (obviously it changes the exponential distribution) that is how different exponential scale distributions relates to real world issues.


Ambassador to the humans
(it is not clear to me what the default sigma is for SAS's random selection from an exponential distributions as their web page does not cover this)
You don't say which page you're referring to but it is probably one of these two (or the 9.3 equivalent I just realize this was the 9.2

I guess this one doesn't explicitly jump out and bite you and say "the parameter is 1" but if you know the form of the distribution it can be inferred that the parameter is 1.

This one does say the parameter is 1.

both of those methods generate from a standard exponential distribution (i.e. the scale parameter is 1). You can modify the scale by multiplying or divide the result by a constant which is what I'm assuming the author is doing to generate according to any arbitrary exponential distribution.


Less is more. Stay pure. Stay poor.

I bet I know your issue, some times SAS flps the direction of one of your quotation marks. It is really hard to see or tell. It does this some times when expecting that mark to be the latter in a pair.

I know you said you typed it but some times it comes up in pasting even your own written code. Every once in awhile I have to delete and rewrite a line or more of code.

Using the " instead of ' works because it is not on the look out for a second ".


Fortran must die
I was referring to the 9.3 documentation for RAND.

This is the function Wicklin emphasizes and thus which I use. According to documentation elsewhere it uses the algorithm which is best in generating pseudorandom numbers (the same one R uses).

He does indeed multiply the scale by multiplying by a constant - whatever sigma is.

As reflected in this code. x = sigma*rand("Exponential");

From his comments I assume this is not entirely arbritrary. That there are reasons to use a specific exponential distribution with a given standard deviation. But I don't know that.


Less is more. Stay pure. Stay poor.
I cut-n-pasted your code and got the same errors. However, I then deleted the lead single quotation mark and retyped it, then did the same for the latter single quotation mark and the code ran fine.