Dear Sas members,
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)
STOCKS
AN8068571086
ANN4327C1220
ANN6748L1027
AT0000603709
AT0000609607
AT0000620158
AT0000633300
AT0000644505
AT0000652011
AT0000676903
AT0000720008
AT0000729108
AT0000737705
AT0000741053
AT0000743059
AT0000746409
AT0000809058
AT0000821103
I have come up with this code but I am stuck
/*create random weights between 0 and 5 for each stock.*/
data Sample1;
set SASUSER.RANDOM_WEIGHTS;
rand = 1+(5-1)*ranuni(692);
if rand ge 0 and rand le 5;
run;
/*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 */
run;
PROC SORT DATA=Sample2;
BY random; /* SORT OBSERVATIONS BY THE RANDOM VECTOR */
run;
Thanks for helping me out if you know the solution...
Kind regards,
Stefaan
Message was edited by: OzoneX15