BookmarkSubscribeRSS Feed
SASuserlot
Barite | Level 11

I am using the following sas macro to batch run every sas program in the given location and create the log and lst files. However, I see the filenames were modifying little bit. is there any it can be fixed? Example: At given folder path I have a sas file 'Test'. When I ran the program it creating the lst and log files but file names are like 'Test.sas' for log file or 'Test.sas' for lst type file. Thank you in advance.

%macro runInParallel(filesLocation);

/* get the list of files */
data filesWithCodes;
  base = "&filesLocation.";
  length file $ 256 folderRef fileRef $ 8;

  folderRef = "_%sysfunc(datetime(), hex6.)0";

  rc=filename(folderRef, base);
  folderid=dopen(folderRef);

  N = dnum(folderId);
  j = 0;
  do i=1 to N; drop i;
    file = dread(folderId, i);
    if upcase(scan(file, -1, ".")) = "SAS" then
      do;
        j+1;
        call symputX(cats("TEST_", j), file, "L");
        output; 
      end;
  end;

  rc = dclose(folderid);
  rc = filename(folderRef);

  call symputX("numberOfTests", j, "L");
  stop;
run;
proc print data = filesWithCodes;
run;

/* setup sas sessions */
%local SASROOT SASEXE SASWORK;
filename sasroot "!SASROOT";
%let SASROOT=%sysfunc(PATHNAME(sasroot));
filename sasroot;
%put *&SASROOT.*;
%let SASEXE=&SASROOT./sas;
%put *&SASEXE.*;
%let SASWORK=%sysfunc(GETOPTION(work));
%put *&SASWORK.*;

%local t;   
systask kill 
  %do t = 1 %to &numberOfTests.;
    sas&t. 
  %end;
wait;

/* run parallel jobs */
/* you can adjust the config file location yourself by editing `-config ""&SASROOT./sasv9.cfg""` */
/* you can adjust outputs and logs locations yourself */
%do t = 1 %to &numberOfTests.;
%local sasstat&t.;
systask command
"""&SASEXE.""
  -sysin ""&filesLocation./&&TEST_&t.""
  -print ""&filesLocation./&&TEST_&t...lst""
    -log ""&filesLocation./&&TEST_&t...log""
 -config ""&SASROOT./sasv9.cfg""
   -work ""&SASWORK.""
 -noterminal
 -rsasuser"
taskname=sas&t.
status=sasstat&t.
NOWAIT /* change it to WAIT if you dont need to run it in parallel */
;
%end;

waitfor _all_
  %do t = 1 %to &numberOfTests.;
    sas&t. 
  %end;
;

data _null_;
  put "NOTE: The End!";
run;

%mend runInParallel;

options NOQUOTELENMAX;
%runInParallel(C:\Users\xx\Desktop\test)
2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

1. Just a note

If you have SAS/Connect, you have this functionality by using MP connect

 

2. Please check

file names are like 'Test.sas' for log file or 'Test.sas' for lst type file.

It looks like you have file extensions hidden in Windows. Disable that nonsense.

 

 

Tom
Super User Tom
Super User

Since you are looking only for filenames that either end in .SAS (or files with no extension that are named just SAS) and then appending either .log or .lst to the names the the actual names of the THREE files will be:

Test.sas
Test.sas.log
Test.sas.lst

If you would rather that they be named:

Test.log
Test.lst

Instead then remove the last 4 characters from your macro variable with the filename.

Either when you write them into the macro variable:

call symputX(cats("TEST_", j), substr(file,1,length(file)-4), "L");

Or when you use them to generate the SAS command.

 

PS To make your first step no match filenames of SAS or sas then make sure the filename actually has a period in it before calling the SCAN() function.

if index(file,'.') and upcase(scan(file, -1, '.'))="SAS" then do;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 2080 views
  • 0 likes
  • 3 in conversation