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
- /
- monte carlo simulation with summation

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-16-2018 08:32 AM

I'm trying to do a monte carlo simulation where I need to sum over the total data set as a last step and can't seem to make it work, let alone do it in a nice way.

I want to simulate the variable A that is made from a number of parameters and the standard normal distribution. From this I want to sum another variable w if A fulfills a specific requirement.

My problem is firstly that i can't find a way to sum these w in the same data step as the simulation of A. Since my data set is about 10 000 rows and i want to do 500 000 simulations I can't have the table growing to 500 000 * 10 000 but rather i want the final table to have the sums of each iteration, in other words it should be 500 000 rows

Furthermore i'm interested in if there is a more elegant way of approaching this problem in terms of the functions used etc.

I'm using SAS 9.3 if its relevant.

Thanks!

this is what i have so far, but it is not working...

data multi;

set multi_base;

do iter = 1 to 2;

L = 0;

A = a1*rand("Normal") +

a2*rand("Normal") +

a3*rand("Normal") +

a4*rand("Normal") +

a5*rand("Normal")

if A < b then L = L + w;

output;

end;

keep iter L;

run;

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

Posted in reply to jan_t_lagen

02-16-2018 08:36 AM

2 questions:

Do you have a SAS/IML license?

What does the data set multi_base look like?

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

Posted in reply to draycut

02-16-2018 08:45 AM

I do not have a SAS/IML licence and multi_base just contains a1-a5, b and w

that are unique for each row

that are unique for each row

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

Posted in reply to jan_t_lagen

02-16-2018 10:00 AM

I assume that if A >= b then L remains unchanged and that value of w is discarded?

Compute the conditional cumulative sum as you go along, but put the OUTPUT statement OUTSIDE the END of the iteration loop.