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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Oligolas
Barite | Level 11

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 -

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Rick_SAS
SAS Super FREQ

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.

Oligolas
Barite | Level 11

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 917 views
  • 3 likes
  • 4 in conversation