I got the following code from online and was wondering if there was a way to efficiently run it multiple times with different combinations of PARAMN, APHASE, and DAYN. I assume a do loop will get me there but I am not at all familiar with how to set one up.
%let NumSamples = 1000;
data sample;
set _trt_;
where paramn = 1 and aphase = 'CHMI 1' and dayn = 1;
keep aval;
proc surveyselect data= sample noprint seed= 1
out= _boot_ (rename= (replicate = sampleid))
method= urs /*resample with replacement*/
samprate= 1 /*each bootstrap sample has N observations*/
reps= &NumSamples; /*generate # bootstrap resamples*/
proc means data= _boot_ noprint;
by sampleid;
freq NumberHits;
var aval;
output out= _boot_med_ median= med;
proc univariate data= _boot_med_ noprint;
var med;
output out= _95ci_ pctlpre= CI95_
pctlpts= 2.5 97.5
pctlname= lb ub;
data _111;
set _95ci_;
statn= 5;
ci = strip(lb)||', '||strip(ub);
paramn = 1; aphase = 'CHMI 1'; dayn = 1;
run;
Mock Dataset:
data have0;
input usubjid $ paramn aphase $ dayn aval @@;
cards;
A 1 CHMI1 1 0.45
A 1 CHMI1 2 0.36
A 1 CHMI1 3 0.66
A 2 CHMI1 1 0.25
A 2 CHMI1 2 0.58
A 2 CHMI1 3 0.55
A 2 CHMI1 4 0.65
A 3 CHMI1 1 0.25
A 3 CHMI1 2 0.85
A 1 CHMI2 1 0.12
A 1 CHMI2 2 0.54
A 1 CHMI2 3 0.98
A 2 CHMI2 1 0.13
A 3 CHMI2 1 0.21
A 3 CHMI2 2 0.48
;
run;
data have;
set have0; output;
set have0; usubjid = 'B'; aval = aval + 0.05; output;
set have0; usubjid = 'C'; aval = aval - 0.1; output;
run;
You could do this yourself, or you could use the existing %BOOT and %BOOTCI macros, and save yourself a lot of programming time.
https://blogs.sas.com/content/iml/2018/07/23/boot-and-bootci-macros-sas.html
You could do this yourself, or you could use the existing %BOOT and %BOOTCI macros, and save yourself a lot of programming time.
https://blogs.sas.com/content/iml/2018/07/23/boot-and-bootci-macros-sas.html
Although that would help me reduce the bootstrap code itself down, I would still need to create different combinations of PARAMN, APHASE, and DAYN to get all the 95% CI that I want. This is the main reason I would like to make a loop.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.