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.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.