BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BY2
Obsidian | Level 7 BY2
Obsidian | Level 7

Yes, n is the total number of rows in source1

Ksharp
Super User

Maybe you need SAS/IML to vectorize your code.

@Rick_SAS 

BY2
Obsidian | Level 7 BY2
Obsidian | Level 7

Unfortunately I do not have license for SAS IML. 

Rick_SAS
SAS Super FREQ

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.

Rick_SAS
SAS Super FREQ

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.

 

 

BY2
Obsidian | Level 7 BY2
Obsidian | Level 7

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. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 4324 views
  • 11 likes
  • 4 in conversation