I have difficulties in selecting a random sample.
I have to create 1000 portfolios. These portfolios have to pick random stocks with weights (ranging from 0 to 0.05) UNTIL the sum of 1 is reached. Which has to change every time a new portoflio is created.
-->So to be clear:
I have 1 portfolio that has to select a stocks with random weights until the weights sum up to 1 or close to one.
Than again I assign random weights to the stocks and create a second portfolio that randomly chooses stocks until the sums of the weights is 1;.. and so on...
The only column I have are the STOCKS (500 stocks-500 rows)
/*create random weights between 0 and 5 for each stock.*/
rand = 1+(5-1)*ranuni(692);
if rand ge 0 and rand le 5;
/*selecting a random sample from a data set is to, first, use a DATA step to generate a random vector,
then use PROC sort to rearrange the data by that random vector and then select first k observations*/
DATA Sample2 ;
SET Sample1 ;
random=RANUNI(-1); /* GENERATE A RANDOM VECTOR */
PROC SORT DATA=Sample2;
BY random; /* SORT OBSERVATIONS BY THE RANDOM VECTOR */
Thanks for helping me out if you know the solution...
It seems that you're is approach is good and that you are stuck on how to increment to weight up to 1. SAS has a RETAIN feature that retains the value from one record to another. See my below code using an example;