SASUnit Examples  Version 1.3.0
_deletescenariofiles.sas
Go to the documentation of this file.
1 
22 %MACRO _deletescenariofiles(i_scnid =
23  );
24 
25  %LOCAL l_nobs l_target;
26 
27  %LET l_target = %_abspath(&g_root, &g_target);
28 
29  %*** Deletion of /rep files *;
30  %_dir(i_path=&l_target./rep/%str(*.*), o_out=dir1);
31  DATA _NULL_;
32  FILE "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas";
33  SET dir1;
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 ');';
38  END;
39  RUN;
40 
41  %*** Deletion of /log files ***;
42  %_dir(i_path=&l_target./log/&i_scnid.%str(*), o_out=dir2);
43  DATA _NULL_;
44  FILE "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas" mod;
45  SET dir2;
46  IF prxmatch("/\/&i_scnid..*$/", filename) THEN DO;
47  PUT '%LET rc=%_delfile(' filename ');' ;
48  END;
49  RUN;
50 
51  %*** Deletion of /tst files ***;
52  %_dir(i_path=&l_target./tst/&i_scnid.%str(*), o_out=dir3);
53  DATA _NULL_;
54  FILE "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas" mod;
55  SET dir3;
56  IF prxmatch("/\/&i_scnid..*$/", filename) THEN DO;
57  PUT '%LET rc=%_delfile(' filename ');';
58  END;
59  RUN;
60 
61  %include "%sysfunc(pathname(work))/_scenarioFilesToDelete.sas";
62 
63  %*** Deletion of /tst folders ***;
64  PROC SQL;
65  CREATE TABLE foldersToDelete AS
66  SELECT distinct tst_scnid, tst_casid, tst_id, lowcase(tst_type) as tst_type
67  FROM target.tst
68  WHERE tst_scnid = &i_scnid.;
69  ;
70  QUIT;
71 
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;
75  DATA _NULL_;
76  FILE "%sysfunc(pathname(work))/_scenarioFoldersToDelete.cmd";
77  SET foldersToDelete;
78  PUT "&g_removedir ""&l_target./tst/_" tst_scnid +(-1)"_" tst_casid +(-1)"_" tst_id +(-1) "_" tst_type +(-1)"""&g_endcommand";
79  RUN;
80  %_executeCMDFile(%sysfunc(pathname(work))/_scenarioFoldersToDelete.cmd);
81  %END;
82 
83 %MEND _deletescenariofiles;