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:
1 | 1 | 0.008272 | 0 | 1 | 2.49670 | 8 | 0.90000 |
---|---|---|---|---|---|---|---|
2 | 1 | 0.008272 | 0 | 1 | 2.50739 | 8 | 0.85000 |
3 | 1 | 0.008272 | 1 | 0 | 2.48662 | 8 | 0.82500 |
4 | 1 | 0.008272 | 1 | 0 | 2.53422 | 8 | 0.81250 |
5 | 1 | 0.008272 | 1 | 0 | 2.56987 | 8 | 0.80625 |
6 | 1 | 0.012790 | 1 | 0 | 2.56987 | 8 | 0.80000 |
7 | 1 | 0.015102 | 1 | 0 | 2.56987 | 8 | 0.60000 |
8 | 1 | 0.026568 | 1 | 0 | 2.56987 | 8 | 0.50000 |
9 | 1 | 0.031404 | 1 | 0 | 2.56987 | 8 | 0.40000 |
10 | 1 | 0.056710 | 1 | 0 | 2.83734 | 8 | 0.40000 |
11 | 2 | 0.007388 | 0 | 1 | 2.50739 | 4 | 0.90000 |
12 | 2 | 0.007388 | 0 | 1 | 2.50739 | 4 | 0.80000 |
13 | 2 | 0.012790 | 0 | 1 | 2.50739 | 4 | 0.60000 |
14 | 2 | 0.012790 | 0 | 1 | 2.50739 | 4 | 0.50000 |
15 | 2 | 0.012790 | 1 | 0 | 2.48662 | 4 | 0.45000 |
16 | 2 | 0.012790 | 1 | 0 | 2.53422 | 4 | 0.40000 |
17 | 2 | 0.015102 | 1 | 0 | 2.53422 | 4 | 0.40000 |
18 | 2 | 0.026568 | 0 | 1 | 2.53611 | 4 | 0.40000 |
19 | 2 | 0.026568 | 0 | 1 | 2.53611 | 4 | 0.40000 |
20 | 2 | 0.056710 | 1 | 0 | 2.83734 | 4 | 0.40000 |
21 | 3 | 0.000713 | 0 | 1 | 2.49670 | 7 | 0.90000 |
22 | 3 | 0.006193 | 1 | 0 | 2.48662 | 7 | 0.80000 |
23 | 3 | 0.015102 | 1 | 0 | 2.48662 | 7 | 0.66667 |
24 | 3 | 0.015102 | 1 | 0 | 2.48662 | 7 | 0.60000 |
25 | 3 | 0.015102 | 1 | 0 | 2.53422 | 7 | 0.56667 |
26 | 3 | 0.026568 | 1 | 0 | 2.53422 | 7 | 0.55000 |
27 | 3 | 0.026568 | 1 | 0 | 2.73459 | 7 | 0.54167 |
28 | 3 | 0.031404 | 0 | 1 | 2.55807 | 7 | 0.53333 |
29 | 3 | 0.032303 | 1 | 0 | 2.83734 | 7 | 0.53333 |
30 | 3 | 0.056710 | 0 | 1 | 2.49329 | 7 | 0.53333 |
31 | 4 | 0.000713 | 0 | 1 | 2.49670 | 4 | 0.90000 |
32 | 4 | 0.006193 | 0 | 1 | 2.49670 | 4 | 0.80000 |
33 | 4 | 0.007388 | 0 | 1 | 2.50739 | 4 | 0.70000 |
34 | 4 | 0.008272 | 1 | 0 | 2.48662 | 4 | 0.64167 |
35 | 4 | 0.012790 | 1 | 0 | 2.53422 | 4 | 0.58333 |
36 | 4 | 0.015102 | 0 | 1 | 2.53611 | 4 | 0.38889 |
37 | 4 | 0.026568 | 0 | 1 | 2.55807 | 4 | 0.29167 |
38 | 4 | 0.031404 | 1 | 0 | 2.56987 | 4 | 0.24306 |
39 | 4 | 0.031404 | 1 | 0 | 2.83734 | 4 | 0.19444 |
40 | 4 | 0.056710 | 0 | 1 | 2.49329 | 4 | 0.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
1 | 1 | 0.008272 | 0 | 1 | 2.49670 | 8 | 0.90000 |
---|---|---|---|---|---|---|---|
2 | 1 | 0.008272 | 0 | 1 | 2.50739 | 8 | 0.85000 |
3 | 1 | 0.008272 | 1 | 0 | 2.48662 | 8 | 0.82500 |
4 | 1 | 0.008272 | 1 | 0 | 2.53422 | 8 | 0.81250 |
5 | 1 | 0.008272 | 1 | 0 | 2.56987 | 8 | 0.80625 |
6 | 1 | 0.012790 | 1 | 0 | 2.56987 | 8 | 0.80000 |
7 | 1 | 0.015102 | 1 | 0 | 2.56987 | 8 | 0.60000 |
8 | 1 | 0.026568 | 1 | 0 | 2.56987 | 8 | 0.50000 |
9 | 1 | 0.031404 | 1 | 0 | 2.56987 | 8 | 0.40000 |
10 | 1 | 0.056710 | 1 | 0 | 2.83734 | 8 | 0.40000 |
test_&p_2
1 | 3 | 0.000713 | 0 | 1 | 2.49670 | 7 | 0.90000 |
---|---|---|---|---|---|---|---|
2 | 3 | 0.006193 | 1 | 0 | 2.48662 | 7 | 0.80000 |
3 | 3 | 0.015102 | 1 | 0 | 2.48662 | 7 | 0.66667 |
4 | 3 | 0.015102 | 1 | 0 | 2.48662 | 7 | 0.60000 |
5 | 3 | 0.015102 | 1 | 0 | 2.53422 | 7 | 0.56667 |
6 | 3 | 0.026568 | 1 | 0 | 2.53422 | 7 | 0.55000 |
7 | 3 | 0.026568 | 1 | 0 | 2.73459 | 7 | 0.54167 |
8 | 3 | 0.031404 | 0 | 1 | 2.55807 | 7 | 0.53333 |
9 | 3 | 0.032303 | 1 | 0 | 2.83734 | 7 | 0.53333 |
10 | 3 | 0.056710 | 0 | 1 | 2.49329 | 7 | 0.53333 |
ETC
THANKS
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
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.