Hi ,
I am writing following the piece of code to bootstrap 5000 bi-variate ("Sharpe" "Treynor") sample values from the file 'rsltdspbetach1' from 'mfsas' library. It is working fine. The issue is I have over 100 such 'rsltdspbetach' files i.e. rsltdspbetach2, ....., rsltdspbetach1, rsltdspbetach100. Each have "Sharpe" "Treynor" in them . How to perform it , given the structure ? Macros are not running inside iml loop. i, j etc causing SAs to stop.
:
proc iml;
%let MyData = mfsas.rsltdspbetach1; %let NumSamples = 5000;
call randseed(12345);
use &MyData;
read all var {"Sharpe" "Treynor" } into X;
close &MyData;
print X;
N=nrow(X); C=ncol(X); print N C ;
*ndx = SampleReplace(1:N, &NumSamples, N);
*Resample from the rows of X. Generate the indices for all bootstrap resamples with a single call;
ndx = Sample(1:N, N // &NumSamples) ;*-ndx will be a &NumSamples x N matrix;
n_ndx=nrow(ndx); p_ndx=ncol(ndx); print n_ndx p_ndx ;
*print (ndx[1:3,1:5]);
*print ndx;
rho = j(&NumSamples, ncol(X)); *Matrix of 1s.This will be used to hold the results i.e. Y matrices;
*print rho;
do i = 1 to &NumSamples ;
rows = ndx[i, ];
*print rows;
Y = X[rows, ];
*print X print Y;
*rho [i+ (i-1)*(N-1) : i+ i*(N-1), 1:C] =Y ; *C=ncol(X);
c=mean(Y);
rho[i,] = c;
end;
create dspch1_shtr_bts from rho; append from rho; close dspch1_shtr_bts;
data mfsas.dspch1_shtr_bts; set dspch1_shtr_bts; run;
end;
quit ;
You cannot run a macro loop in a SAS procedure, you can only use it to create code for you. Creating dynamic code is the main purpose of the macro processor.
You don't need a macro. Just use a SAS/IML DO loop to loop over the data sets and do whatever computtion you want.
To loop over data sets, see the article "Read data sets that are specified by an array of names."
The code will look something like this (untested):
do i = 1 to 100;
dsname = "mfsas.rsltdspbetach" + strip(char(i)); /* loop over data sets */
use (dsname);
/* computation here */
close (dsname);
end;
In IML, CALL EXECUTEFILE() is very useful tool for such kind of scenario . http://blogs.sas.com/content/iml/2015/06/15/executefile.html
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.