BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

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
1 ACCEPTED SOLUTION

Accepted Solutions
SteveDenham
Jade | Level 19

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

1 REPLY 1
SteveDenham
Jade | Level 19

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

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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