turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Simulation of normal distribution

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-01-2015 12:29 PM

Hi,

I am doing simulation of normal distribution with RAND and use the same SEED but every time I get different data.

What could be wrong?

Here is the code:

**data** normal;

seed =**1976**;

do stickprov = **1** to **100**;

do obs = **1** to **50**;

x = rand ('normal',**2.2**,**1**);

y = rand ('normal', **2.2**,**1**);

output;

end;

end;

drop seed;

**run**;

I look forward to replies.

Thank you in advance.

Regards,

Yuliya

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-01-2015 12:35 PM

From RAND function documentation here

**Generating Random Numbers**

The RAND function generates random numbers from various continuous and discrete distributions. Wherever possible, the simplest form of the distribution is used.

The RAND function uses the Mersenne-Twister random number generator (RNG) that was developed by Matsumoto and Nishimura (1998). The random number generator has a very long period (219937 – 1) and very good statistical properties. The period is a Mersenne prime, which contributes to the naming of the RNG. The algorithm is a twisted generalized feedback shift register (TGFSR) that explains the latter part of the name. The TGFSR gives the RNG a very high order of equidistribution (623-dimensional with 32-bit accuracy), which means that there is a very small correlation between successive vectors of 623 pseudo-random numbers.

The RAND function is started with a single seed. However, the state of the process cannot be captured by a single seed. You cannot stop and restart the generator from its stopping point.

Reproducing a Random Number Stream

If you want to create reproducible streams of random numbers, then use the CALL STREAMINIT routine to specify a seed value for random number generation. Use the CALL STREAMINIT routine once per DATA step before any invocation of the RAND function. If you omit the call to the CALL STREAMINIT routine (or if you specify a non-positive seed value in the CALL STREAMINIT routine), then RAND uses a call to the system clock to seed itself. For more information, see CALL STREAMINIT Creating a Reproducible Stream of Random Numbers.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-01-2015 01:13 PM

You create a variable called SEED, but don't actually use it for anything You need to use CALL STREAMINIT() to apply the seed.

```
data normal;
seed =1976;
call streaminit(seed);
do stickprov = 1 to 100;
do obs = 1 to 50;
x = rand ('normal',2.2,1);
y = rand ('normal', 2.2,1);
output;
end;
end;
drop seed;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-02-2015 04:28 AM

Thank you very much. I am a novice in SAS )

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-02-2015 11:20 AM

If you plan on doing much simulation, you might consider reading some of the Simulation articles on The DO Loop blog. Start with this one about Simulation in SAS.