SASUnit Examples  Version 1.5.0
_dependency_agg.sas
Go to the documentation of this file.
1 
21 %MACRO _dependency_agg(i_path =
22  ,o_file =
23  );
24 
25 
26 
27  %LOCAL l_countObs json_dir l_pgmName l_filename;
28 
29  %_tempFileName(json_dir);
30  %_dir(i_path = &i_path
31  ,o_out = &json_dir);
32 
33  /* get number of obs */
34  PROC SQL NOPRINT;
35  SELECT count(*)
36  INTO :l_countObs
37  FROM &json_dir.
38  ;
39  QUIT;
40 
41  FILENAME aggregJS "&o_file";
42 
43  /* Create JavaScript file */
44  DATA _NULL_;
45  FILE aggregJS;
46  PUT 'var allGraphs = [';
47  RUN;
48 
49  /* initiate loop over all data sets referenced in data set */
50  %DO l_i=1 %TO &l_countObs;
51 
52  DATA _NULL_;
53  * read one observation;
54  SET &json_dir. (firstobs=&l_i. obs=&l_i.);
55  len = length(membername)-12;
56  CALL SYMPUT("l_pgmName", substr(membername,1,len));
57  CALL SYMPUT("l_filename", trim(filename));
58  RUN;
59 
60  %IF %EVAL(%SYSFUNC(mod(&l_i,2)) = 1) %THEN %DO;
61  DATA _NULL_;
62  FILE aggregJS mod;
63  helper = catt('{ "id" : "', "&l_pgmName", '"');
64  put helper;
65  put ', "called" :';
66  RUN;
67 
68  DATA _NULL_;
69  INFILE "&l_filename";
70  Input;
71  FILE aggregJS mod;
72  put _infile_;
73  RUN;
74  %END;
75  %ELSE %DO;
76  DATA _NULL_;
77  FILE aggregJS mod;
78  helper = ', "caller" :';
79  put helper;
80  RUN;
81  DATA _NULL_;
82  INFILE "&l_filename";
83  Input;
84  FILE aggregJS mod;
85  put _infile_;
86  RUN;
87 
88  DATA _NULL_;
89  FILE aggregJS mod;
90  helper = "} // " || "&l_pgmName";
91  put helper;
92  %IF %sysfunc(strip(&l_countObs)) NE %sysfunc(strip(&l_i)) %THEN %DO;
93  put ',';
94  %END;
95  RUN;
96 
97  %END;
98  %END;
99 
100  /* Finalize JavaScript file */
101  DATA _NULL_;
102  FILE aggregJS mod;
103  put '];';
104  RUN;
105 
106  FILENAME aggregJS;
107 
108 %MEND _dependency_agg;