Thanks for providing more complete information.
On page 3 of your Word document (which I read using the document preview feature of the forum as no MS Word is installed on my SAS workstation) you show a DATA step that you say is "not working with the purpose". However, if I run this and the two preceding steps using a simplified version of your LOANS dataset, it appears to work perfectly: It creates 10 observations for each Borrower_ID-Scenario combination.
Here are the first three observations for borrower ID B00000 in the "Adverse" scenario (i.e., observations 11 through 13 of the output dataset MONTECARLO), limited to the most important variables:
Borrower_ random_ random_ ID Scenario PD LGD Sim_PD Sim_LGD sim_id PD LGD sim_loss B00000 Adverse 0.2324 0.58 0.2905 0.638 1 0.29511 0.70829 5596.03 B00000 Adverse 0.2324 0.58 0.2905 0.638 2 0.28944 0.59881 4640.23 B00000 Adverse 0.2324 0.58 0.2905 0.638 3 0.29920 0.64346 5154.29
Variables PD and LGD are copied from the LOANS dataset, Sim_PD and Sim_LGD were created in your PROC SQL step. In the DO loop of the final DATA step (do sim_id = 1 to 10;) the randomly varying values of random_PD and random_LGD were generated and used in the calculation of sim_loss. (My suggested renaming of variables would have applied to a PORTFOLIO_SIM dataset using the variable names from the LOANS dataset, which turned out to be different datasets, so no renaming is necessary.)
So, while the first six of the variables shown above have necessarily the same values in these three observations, the newly computed last three variables exhibit the random variation to be expected from a Monte Carlo simulation. Why do you think that these results are not suitable for your purposes?
@skumar46 wrote:
If you are from Sas team, can we connect through zoom/ teams?
No, I am not affiliated with SAS Institute Inc. Like most of the other forum members I am a volunteer, just another SAS user like you (with 27 years of SAS experience, though), helping others in parallel to my actual work.
Thank you so much for prompt response. I am happy to see that you have got my questions well and will be getting 100% solution soon. Please refer to the following mentioned by you quoted by me below. With the code # 4 titled "/* Step 4: Monte Carlo Simulation - Run 10 Iterations for Random Loss Outcomes */" in my coding script whose result/output pasted in attached ms word. You can see that for sim_id = 1 to 10, for the borrower id :B0000 under baselines scenerio, i am getting same result for sim_PD= 0.2324, sim_LGD = 0.58, exp loss: 3,608.73 for all sim_id from 1 to 10, why these are not changing. Now, i understand that like you added three last columnns i.e random_PD random_LGD & sim_loss but that not fetched by sas on demand when i run this in sam on demand. I dont know what issue i am facing ? Are you using also sas on demand? If you changed step# 4 little bit then pls share code with me please here.
Quote
"In the DO loop of the final DATA step (do sim_id = 1 to 10;) the randomly varying values of random_PD and random_LGD were generated and used in the calculation of sim_loss"
@skumar46 wrote:
(...) for the borrower id :B0000 under baselines scenerio, i am getting same result for sim_PD= 0.2324, sim_LGD = 0.58, exp loss: 3,608.73 for all sim_id from 1 to 10, why these are not changing.
This is because these three variables were created in your PROC SQL step: Look at the first occurrences of their names in your code. Sim_PD and Sim_LGD are derived from PD and LGD, respectively, in CASE-WHEN expressions. Expected_Loss is the result of a multiplication involving Sim_PD, Sim_LGD and two other factors.
In the final DATA step, Sim_PD and Sim_LGD are used as arguments of the RAND function, which does not change their values. Instead, the randomly changing values returned by this function are stored in variables named random_PD and random_LGD. These, in turn, are used in the calculation of variable sim_loss.
As a result, the only variables that have a chance to differ between observations in dataset MONTECARLO with the same Borrower_ID and Scenario are: random_PD, random_LGD, sim_loss and (trivially) sim_id. All other variables just contribute 10 copies (per Borrower_ID-Scenario combination) of their corresponding value in dataset PORTFOLIO_SIM.
@skumar46 wrote:
Now, i understand that like you added three last columnns i.e random_PD random_LGD & sim_loss but that not fetched by sas on demand when i run this in sam on demand.
These variables must be contained in dataset MONTECARLO if the DATA step creating it ran successfully. You may need to scroll your output to the rightmost columns to make them visible in the window. Or use the VAR statement of PROC PRINT to select and order the most important variables to be displayed in the output.
Example:
proc print data=montecarlo(obs=10);
var Borrower_ID Scenario sim_id random_PD random_LGD sim_loss;
run;
@skumar46 wrote:
Are you using also sas on demand?
No, I have never used SAS OnDemand because I have always used SAS software provided by my employers or clients and, since 2015, my own local SAS installation.
Thank you so much for all your time to reply my queries patiently. I understand that i need to do a lot of pratcice for improving my basic. While i am able to view the random values for PG & LGD but dont undersrand that why values i am getting differ from the 3 rows shared in your reply. Pls refer last page of ms word.
Is it because that these randoms values will be different each type i run the code because of random nature like you and me getting different values?
You're welcome.
The (pseudo-)random values of random_PD and random_LGD created by the RAND function depend on the random seed used in the CALL STREAMINIT routine (the value 1 in our code), the random-number generator (MTHybrid is the default, but only since SAS 9.4M3), the order in which they are calculated and possibly even on the platform (hardware and operating system).
In our case the order of calculations might be the reason why we get different results. For example, if scenario "Adverse" came before "Baseline" in dataset PORTFOLIO_SIM, the random values for "Adverse" would be different from what they are with "Baseline" being the first scenario. The sort order of the borrower IDs is similarly important. Note that since PORTFOLIO_SIM was created by PROC SQL without an ORDER BY clause, the order of observations in PORTFOLIO_SIM can be different on different computers, even using the same program code!
I have just created one million pairs of random_PD and random_LGD values based on the Sim_PD and Sim_LGD values of the case in question and I found your values in observations 3901, 3902, ..., 3910 of this series. So, maybe 3900 other values had been created before due to sort order differences or other technical reasons (consider perhaps multi-threaded parallel computing on the server SAS OnDemand connects to).
As a matter of fact, you don't have to worry about those differences. Your values are valid and it is reassuring that I could reproduce them on my computer.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Ready to level-up your skills? Choose your own adventure.