SASUnit Examples  Version 1.5.0
_deletescenariofiles.sas
Go to the documentation of this file.
1 
23 %MACRO _deletescenariofiles(i_scenariosToRun=
24  );
25  %LOCAL l_len l_nobs l_obs l_scnDel l_target l_foldersToDelete l_filesToDelete;
26  %LET l_target = %_abspath(&g_root, &g_target);
27 
28  PROC SQL NOPRINT;
29  CREATE TABLE scenarioFilesToDelete AS
30  SELECT scn_id
31  FROM &i_scenariosToRun AS s
32  WHERE s.dorun = 1 AND scn_id IN (SELECT scn_id FROM target.scn)
33  ;
34  SELECT scn_id into :l_scnDel separated by ','
35  FROM scenarioFilesToDelete
36  ;
37  SELECT count(scn_id) AS cnt into :l_obs
38  FROM scenarioFilesToDelete
39  ;
40  QUIT;
41 
42  %IF &l_obs GT 0 %THEN %DO;
43  %*** Dir for deletion of /rep, /tst and /log files *;
44  %_dir(i_path=&l_target./rep/, o_out=rep);
45  %_dir(i_path=&l_target./log/, o_out=log);
46  %_dir(i_path=&l_target./tst/, o_out=tst);
47 
48  %let l_filesToDelete = %sysfunc(pathname(work))/_scenarioFilesToDelete.sas;
49  DATA _NULL_;
50  FILE "&l_filesToDelete";
51  SET scenarioFilesToDelete nobs=numobs_dorun;
52 
53  DO i=1 TO numobs_log;
54  SET log nobs=numobs_log point=i;
55  IF index(membername, put(scn_id,z3.)) = 1 THEN DO;
56  PUT '%PUT Delete ' filename ' RC: %_delfile(' filename ');';
57  END;
58  END;
59  DO j=1 TO numobs_rep;
60  SET rep nobs=numobs_rep point=j;
61  IF index(membername, put(scn_id,z3.)) = 1 OR
62  index(membername, catt("_", put(scn_id,z3.))) = 1 OR
63  index(membername, catt("cas_", put(scn_id,z3.),"_")) = 1 OR
64  index(membername, catt("tcg_", put(scn_id,z3.))) = 1
65  THEN DO;
66  PUT '%PUT Delete ' filename ' RC: %_delfile(' filename ');';
67  END;
68  END;
69  DO k=1 TO numobs_tst;
70  SET tst nobs=numobs_tst point=k;
71  IF index(membername, put(scn_id,z3.)) = 1 THEN DO;
72  PUT '%PUT Delete ' filename ' RC: %_delfile(' filename ');';
73  END;
74  END;
75  RUN;
76  %INCLUDE "&l_filesToDelete.";
77  %LET l_rc=%_delfile(&l_filesToDelete.);
78 
79  %*** Deletion of /tst folders ***;
80  %_dir(i_path=&l_target./tst/, i_recursive=1, o_out=tst_folder);
81 
82  %LET l_len = %sysfunc(length(&l_target./tst/));
83 
84  DATA foldersToDelete;
85  SET tst_folder;
86  part = substr(filename, &l_len+1);
87  pos = index(part, "/");
88  IF pos > 0 THEN DO;
89  folder = substr(part, 1, pos-1);
90  id = input(substr(folder,2,3),3.);
91  IF id IN (&l_scnDel) THEN DO;
92  OUTPUT;
93  END;
94  END;
95  KEEP id folder;
96  RUN;
97 
98  %LET l_nobs = %_nobs(foldersToDelete);
99 
100  %*** Write and execute cmd file only if table foldersToDelete is not empty ***;
101  %IF &l_nobs > 0 %THEN %DO;
102  PROC SORT DATA = foldersToDelete nodupkey;
103  BY folder;
104  RUN;
105 
106  %let l_foldersToDelete = %sysfunc(pathname(work))/_scenarioFoldersToDelete.cmd;
107  DATA _NULL_;
108  FILE "&l_foldersToDelete";
109  SET foldersToDelete;
110  PUT "&g_removedir ""&l_target./tst/" folder+(-1)"""&g_endcommand";
111  RUN;
112  %_executeCMDFile(&l_foldersToDelete);
113  %LET l_rc=%_delfile(&l_foldersToDelete);
114 
115 
116  %END;
117  %END;
118 %MEND _deletescenariofiles;