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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

View solution in original post

8 REPLIES 8
ballardw
Super User

If this a program that will run under SAS it may be easier to use something like:

%include "C:\Users\KMarino\*.flexmirt";

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

dkb
Quartz | Level 8 dkb
Quartz | Level 8

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;

KateM
Calcite | Level 5

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?

data_null__
Jade | Level 19

You might thing about what is happening when you COMPRESS.

Tom
Super User Tom
Super User

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;

jakarman
Barite | Level 11

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

---->-- ja karman --<-----
KateM
Calcite | Level 5

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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 8 replies
  • 1318 views
  • 6 likes
  • 7 in conversation