I used SAS to create 60,000 flexMIRT syntax files for a simulation study. Now I need to compile those file names into a single csv batch file. I've created the batch macro below but I keep overwriting the batch file instead of amending it as I try and loop through the file names. I think I need to create a DO loop within the batch macro. The batch file should look like:
C:\Users\KMarino\300_10_0.11_10_1.flexmirt
C:\Users\KMarino\300_10_0.11_10_2.flexmirt
C:\Users\KMarino\300_10_0.11_10_3.flexmirt
......
C:\Users\KMarino\300_10_0.11_10_250.flexmirt
.....
C:\Users\KMarino\1000_10_0.11_10_1.flexmirt
.....
C:\Users\KMarino\300_10_0.11_10_250.flexmirt
How can I modify the macro below to appropriately compile all the files?
%MACRO batch(I=, ss=, cl=, bv=, it=, rep=);
DATA _NULL_;
FILE "C:\Users\KMarino\Dropbox\Dissertation\Data Generation\For Dissertation\SAS Control Files\flexMIRTsim.BATRUN.csv";
PUT #&I @1 "C:\Users\KMarino\&ss._&cl._&bv._&it._&rep..flexMIRT"
;
RUN;
%mend batch;
data _null_;
DO ss=300, 1000, 5000;
DO cl=10, 60, 100, 150;
DO it=10, 20, 50, 70;
DO BV=0.053, 0.11, 0.25, 0.43, 1.00
DO it=10, 20, 50, 70;
Do rep=1 to 250;
_N_+1;
call execute (catt('%batch (I='|| put(_N_+1,2.)||', ss=', ss ,', cl=', cl ,', bv=',bv,', it=',it,', rep=',rep,')')) ;
end;
end;
end;
end;
end;
end;
run;
Add the operand "MOD" to your FILE statement - it will be ignored by SAS on the first execution of the invoked DATA _NULL_ step.
Scott Barry
SBBWorks, Inc.
If this a program that will run under SAS it may be easier to use something like:
%include "C:\Users\KMarino\*.flexmirt";
Add the operand "MOD" to your FILE statement - it will be ignored by SAS on the first execution of the invoked DATA _NULL_ step.
Scott Barry
SBBWorks, Inc.
Alternatively it could be done in a single data step without using a macro, something like this :
data _null_;
FILE "C:\Users\KMarino\Dropbox\Dissertation\Data Generation\For Dissertation\SAS Control Files\flexMIRTsim.BATRUN.csv";
DO ss='300', '1000', '5000';
DO cl='10', '60', '100', '150';
DO it='10', '20', '50', '70';
DO BV='0.053', '0.11', '0.25', '0.43', '1.00';
DO it='10', '20', '50', '70';
Do rep=1 to 250;
string= compress('C:\Users\KMarino\' !! ss !! '_' !! cl !! '_' !! bv !! '_' !! it !! '_' !! put(rep, 3.) !! '.flexMIRT', ' ');
PUT @1 string;
end;
end;
end;
end;
end;
end;
run;
This worked perfectly except it compressed the file name and deleted the spaces. The true path is C:\Users\KMarino\Dropbox\Dissertation\Data Generation\For Dissertation\Simulation Syntax\filename.flexMIRT.
It deleted the space between "Data Generation", "For Dissertation" and "Simulation Syntax". Is there a way to avoid that?
You might thing about what is happening when you COMPRESS.
1) Why not make the list while you make the files? Either as a data set or into the text file.
2) Since you already have the files why not just use DIR command to get the list? Does the order matter? And if so is it different than the order that DIR will return.
data _null_;
file
"C:\Users\KMarino\Dropbox\Dissertation\Data Generation\For Dissertation\SAS Control Files\flexMIRTsim.BATRUN.csv";
infile 'dir /b C:\Users\KMarino\*.flexmirt' pipe;
input;
put _infile_;
run;
Use the mod option with the file-statement when you do not want to overwrite but append the csv file SAS(R) 9.4 Statements: Reference, Third Edition
Thanks for all the suggestions! The MOD statement worked after some further modification of the original syntax but now I've also learned some new commands from the other suggestions. Thanks so much for the help!
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!
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.