How to do one at a time random selection with replacement within a macro

Accepted Solution Solved
Reply
Super Contributor
Posts: 297
Accepted Solution

How to do one at a time random selection with replacement within a macro

Hello the code below is within a macro and it will create the data set below

data tes_&p;

set tes_&p;

if _n_ = 10 then censored = 0;

drop alpha1 seed  i beta1 beta2 lambdaT lambdaC er c c1 c2 t R y1;

run;

proc surveyselect data=tes_&p  method = urs sampsize = 10 OUTHITS

     reps=4 seed=12345 out=test_&p;

run;

OUTPUT which i do not like:

110.008272012.4967080.90000
210.008272012.5073980.85000
310.008272102.4866280.82500
410.008272102.5342280.81250
510.008272102.5698780.80625
610.012790102.5698780.80000
710.015102102.5698780.60000
810.026568102.5698780.50000
910.031404102.5698780.40000
1010.056710102.8373480.40000
1120.007388012.5073940.90000
1220.007388012.5073940.80000
1320.012790012.5073940.60000
1420.012790012.5073940.50000
1520.012790102.4866240.45000
1620.012790102.5342240.40000
1720.015102102.5342240.40000
1820.026568012.5361140.40000
1920.026568012.5361140.40000
2020.056710102.8373440.40000
2130.000713012.4967070.90000
2230.006193102.4866270.80000
2330.015102102.4866270.66667
2430.015102102.4866270.60000
2530.015102102.5342270.56667
2630.026568102.5342270.55000
2730.026568102.7345970.54167
2830.031404012.5580770.53333
2930.032303102.8373470.53333
3030.056710012.4932970.53333
3140.000713012.4967040.90000
3240.006193012.4967040.80000
3340.007388012.5073940.70000
3440.008272102.4866240.64167
3540.012790102.5342240.58333
3640.015102012.5361140.38889
3740.026568012.5580740.29167
3840.031404102.5698740.24306
3940.031404102.8373440.19444
4040.056710012.4932940.19444

BUT this is not what I want, i want to loop it such that rather than having a data set of 40 with replicate from 1 to 4.

I want the simple random sample to select one data set at a time and loop 4 times. That is what I want are 4 data set for this simple random sample like test_&p_1 ,

test_&p_2, test_&p_3, test_&p_4. This might be wrong notation but I am just using this for someone to uderstand what I want to do.

Poorly written like this, within a macro

do i=1 to 4;

proc surveyselect data=tes_&p  method = urs sampsize = 10 OUTHITS

     reps=1 seed=12345 out=test_&p;

run

end


test_&p_1


110.008272012.4967080.90000
210.008272012.5073980.85000
310.008272102.4866280.82500
410.008272102.5342280.81250
510.008272102.5698780.80625
610.012790102.5698780.80000
710.015102102.5698780.60000
810.026568102.5698780.50000
910.031404102.5698780.40000
1010.056710102.8373480.40000


test_&p_2

130.000713012.4967070.90000
230.006193102.4866270.80000
330.015102102.4866270.66667
430.015102102.4866270.60000
530.015102102.5342270.56667
630.026568102.5342270.55000
730.026568102.7345970.54167
830.031404012.5580770.53333
930.032303102.8373470.53333
1030.056710012.4932970.53333

ETC

THANKS

t

Accepted Solutions
Solution
‎11-05-2013 09:17 AM
Respected Advisor
Posts: 2,655

Re: How to do one at a time random selection with replacement within a macro

Would the following accomplish what you are looking for:

data test_&p_1 test_&p_2 test_&p_3 test_&p_4;

set test_&p;

index=floor(_n_ - 1,10) + 1;

if index=1 then output test_&p_1;

     else if index=2 then output test_&p_2;

          else if index=3 then output test_&p_3;

               else if index=4 then output test_&p_4;

run;

Steve Denham

View solution in original post


All Replies
Solution
‎11-05-2013 09:17 AM
Respected Advisor
Posts: 2,655

Re: How to do one at a time random selection with replacement within a macro

Would the following accomplish what you are looking for:

data test_&p_1 test_&p_2 test_&p_3 test_&p_4;

set test_&p;

index=floor(_n_ - 1,10) + 1;

if index=1 then output test_&p_1;

     else if index=2 then output test_&p_2;

          else if index=3 then output test_&p_3;

               else if index=4 then output test_&p_4;

run;

Steve Denham

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 158 views
  • 0 likes
  • 2 in conversation