22 %MACRO _deletescenariofiles(i_scnid =
 
   25    %LOCAL l_nobs l_target;
 
   27    %LET l_target = %_abspath(&g_root, &g_target);
 
   29    %*** Deletion of /rep files *;
 
   30    %_dir(i_path=&l_target./rep/%str(*.*), o_out=dir1);
 
   32       FILE 
"%sysfunc(pathname(work))/_scenarioFilesToDelete.sas";
 
   34       IF prxmatch(
"/rep\/&i_scnid..*$/", filename) OR 
 
   35          prxmatch("/rep\/_&i_scnid._.*$/", filename) OR 
 
   36          prxmatch("/rep\/cas_&i_scnid._.*$/", filename) THEN DO;
 
   37          PUT '%PUT Delete ' filename ' RC: %_delfile(' filename ');';
 
   41    %*** Deletion of /log files ***;
 
   42    %_dir(i_path=&l_target./log/&i_scnid.%str(*), o_out=dir2);
 
   44       FILE "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas" mod;
 
   46       IF prxmatch("/\/&i_scnid..*$/", filename) THEN DO; 
 
   47          PUT '%LET rc=%_delfile(' filename ');' ;
 
   51    %*** Deletion of /tst files ***;
 
   52    %_dir(i_path=&l_target./tst/&i_scnid.%str(*), o_out=dir3);
 
   54       FILE "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas" mod;
 
   56       IF prxmatch("/\/&i_scnid..*$/", filename) THEN DO;
 
   57          PUT '%LET rc=%_delfile(' filename ');';
 
   61    %include "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas";
 
   63    %*** Deletion of /tst folders ***;
 
   65      CREATE TABLE foldersToDelete AS
 
   66      SELECT distinct tst_scnid, tst_casid, tst_id, lowcase(tst_type) as tst_type
 
   68      WHERE tst_scnid = &i_scnid.;
 
   72    %LET l_nobs = %_nobs(foldersToDelete);
 
   73    %*** Write and execute cmd file only if table foldersToDelete is not empty ***;
 
   74    %IF &l_nobs > 0 %THEN %DO;
 
   76          FILE "%sysfunc(pathname(work))/_scenarioFoldersToDelete.cmd";
 
   78          PUT "&g_removedir ""&l_target./tst/_" tst_scnid +(-1)"_" tst_casid +(-1)"_" tst_id +(-1) "_" tst_type +(-1)"""&g_endcommand";
 
   80       %_executeCMDFile(%sysfunc(pathname(work))/_scenarioFoldersToDelete.cmd);
 
   83 %MEND _deletescenariofiles;