Yes, n is the total number of rows in source1
Maybe you need SAS/IML to vectorize your code.
Unfortunately I do not have license for SAS IML.
To improve the efficiency of your simulation, please follow the tips in "Simulation in SAS: The slow way or the BY way" In brief, replace the macro loop with BY-group processing.
It looks like your simulation is trying to generate a random normal variate by using the polar generation method. You can replace all the DO UNTIL loops with a single call to the built-in RAND("Normal") function.
It also looks like you are looking at some correlated bivariate normal variables, but I can't determine what you are trying to accomplish. If you tell us what you want the simulation to do, there is probably a simpler (and faster) way to accomplish it.
Yes, I am trying to generate a random normal variate by using box muller transformation method.
The ultimate goal of this simulation is to obtain the sum of two variables (sum_sim_ML & sum_sim_GL) with 1 million simulation. Let's use sum_sim_ML as the example. The equation of the both variables are similar as shown below.
if mod(n,2)=0 then do; if r * ho * &&sim_1&i + sqrt(1-(r*ho)**2)*sim_m1 < P then sim_ML = E*L; else sim_ML = 0; end; else if mod(n,2)=1 then do; if r * ho * &&sim_1&i + sqrt(1-(r*ho)**2)*sim_m2 < P then sim_ML = E*L; else sim_ML = 0; end;
/* where r, ho, E, L are from source1 table while sim_1, sim_m1 and sim_m2 are randon generating numbers (rng). Note: n is the total observation from source1 table. */
For each simulation (i=1 to 1,000,000), for example, when i=1, sim_1 is applied across all 4000 observations. However, sim_m1 and sim_m2 are RNG and should be different from every observations. After obtaining the parameters of the equation, each observation will have different sim_ML. Then, I use proc sql to get the summation of sim_ML. Finally, I compile all simulation of sum_sim_ML using proc append.
I hope this explains well.
Feel free to let me know if any further clarification is needed.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.