Dear All,
I have a macro that calculates KS, GINI, ROC of a credit risk model. Using that, I have to do a Bootstrapping validation so first I created a BootSample using the proc surveyselect command. The Bootsample contains 5,000 random samples. Each sample contains around 1500 records. How do I execute the macro for each of the samples in my dataset?
one way could be to run your macro with a call execute command.
To guaranty a better debugging I'd rather construct a loop over your macro that will filter your input dataset on the Bootsample you would like to process.
%MACRO doit(BootSampleStart=,BootSampleStop=);
%DO i=&BootSampleStart. %TO &BootSampleStop.;
%put NOTE: Processing BootSample &i.;
/*Your code*/
DATA _tmp;
SET have;
where BootSample=&i.;
RUN;
%YourMacro(inputDataset=_tmp <,your parameters>);
PROC DATASETS lib=work nolist;delete _tmp; RUN;QUIT;
%END;
%MEND doit;
** call example:;
%doit(BootSampleStart=1526,BootSampleStop=1528);
- Cheers -
Everything you could possibly want to know about how to do a bootstrap in SAS from @Rick_SAS
https://blogs.sas.com/content/iml/2018/12/12/essential-guide-bootstrapping-sas.html
In general, running a statistic on each bootstrap sample will be slower than performing a BY group analysis on the output from PROC SURVEYSELECT where the Replicate variable is used as the BY variable. For example, you can see "The bootstrap method in SAS: A t test example"
Did you write the macro yourself? (Or at least understand the contents of the macro?) If so, it would be efficient to rewrite the analysis to directly use the output from SURVEYSELECT.
If you are a beginner and do not understand the macro, then you might be forced to use the slow method. For the slow method, you have a macro loop (say, %DO i = 1 %to 5000) and you use
WHERE REPLICATE=&i;
to subset the bootstrap samples.
one way could be to run your macro with a call execute command.
To guaranty a better debugging I'd rather construct a loop over your macro that will filter your input dataset on the Bootsample you would like to process.
%MACRO doit(BootSampleStart=,BootSampleStop=);
%DO i=&BootSampleStart. %TO &BootSampleStop.;
%put NOTE: Processing BootSample &i.;
/*Your code*/
DATA _tmp;
SET have;
where BootSample=&i.;
RUN;
%YourMacro(inputDataset=_tmp <,your parameters>);
PROC DATASETS lib=work nolist;delete _tmp; RUN;QUIT;
%END;
%MEND doit;
** call example:;
%doit(BootSampleStart=1526,BootSampleStop=1528);
- Cheers -
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.