Hello, How can I fix this by maintaining %do u=1 %to 20; .........%end
data new;
set new;
run;
%do u=1 %to 20;
proc surveyselect data=new method = urs sampsize = 141 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
ERROR: The %DO statement is not valid in open code.
CODES..........
%end;
Do you do something in the CODES... part that modifies the output data sets?
when I ran your code like this, it worked:
%MACRO DO_BRANCH;
%do u=1 %to 4;
proc surveyselect data=SASHELP.CLASS method = urs sampsize = 141 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
/*CODES.....*/
%end;
%MEND DO_BRANCH;
%DO_BRANCH;
By having it in closed code (that is, wrap it into a macro definition).
Hi, for a longer explanation of what LinusH posted, please see my paper "Macro Basics for New SAS Users". If you are struggling with the correct usage for %DO, it is possible that the paper will explain that in more detail and, the rest of the paper might be useful too.
http://support.sas.com/resources/papers/proceedings13/120-2013.pdf
Cynthia
SURVERSELECT has features that should eliminate the need to MACRO look it.
I put it in a macro it runs but no data is created. The data set test is real data that I want to do random sample with replacement. I can not use the option in proc surveyselec that does not require macro because of some computations that were performed in the code
data test;
set test;
run;
%MACRO DO_BRANCH;
%do u=1 %to 20;
proc surveyselect data=test method = urs sampsize = 141 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
ERROR: The %DO statement is not valid in open code.
CODES..........
%end;
%MEND DO_BRANCH;
I think what you need to do is:
%MACRO DO_BRANCH;
%do u=1 %to 20;
proc surveyselect data=test method = urs sampsize = 141 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
CODES.....
%end;
%MEND DO_BRANCH;
%DO_BRANCH
Regards,
Thanks; I ran the code but surveyselect created just new_1 and no data from new_2 to new_20
I ran the code:
%MACRO DO_BRANCH;
%do u=1 %to 20;
proc surveyselect data=test method = urs sampsize = 141 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
CODES.....
%end;
%MEND DO_BRANCH;
%DO_BRANCH;
The following code works just fine when testing
%MACRO DO_BRANCH;
%do u=1 %to 20;
proc surveyselect data=sashelp.class method = urs sampsize = 14 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
%end;
%MEND DO_BRANCH;
%DO_BRANCH;
However, 2 important things to note. Since all procedure resets to the start of the seed, your current implementation would yield new_1=new_2=...=new_20. That is, the exact same 141 records would be selected.
I suspect its the part in CODES... that triggers your empty new_2 to new_20
As DN pointed out, a more natural approach would be to use REPS=20 and then split the resulting file BY REPLICATE (the automatically generated variable listing the count of REPS). This would clear your issue with having to change seeds each time as then it keeps on drawing numbers from the same seed rather than reseting at the beginning of the seed for each procedure iteration.
Do you do something in the CODES... part that modifies the output data sets?
when I ran your code like this, it worked:
%MACRO DO_BRANCH;
%do u=1 %to 4;
proc surveyselect data=SASHELP.CLASS method = urs sampsize = 141 OUTHITS
reps=1 seed=1234100 out=new_&u;
run;
/*CODES.....*/
%end;
%MEND DO_BRANCH;
%DO_BRANCH;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.