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

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

--
Paige Miller

View solution in original post

3 REPLIES 3
mariko5797
Pyrite | Level 9
EDIT: the sample dataset will come from HAVE not _TRT_ in this case
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
mariko5797
Pyrite | Level 9

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 715 views
  • 0 likes
  • 2 in conversation