SAS Documentation
SASĀ® Solution for Stress Testing
Reference manual - version 08.2021
Loading...
Searching...
No Matches
irm_set_fa_sasautos.sas
1%macro irm_set_fa_sasautos(fa_id =
2 , fa_path =
3 , mode = insert
4 , insert_before =
5 , insert_after =
6 , outvar_prefix =
7 , limit = 0
8 , force_flg = N
9 );
10
11 %local
12 swc_property_value
13 path
14 TotPaths
15 TotFas
16 TotFaInsert
17 processed
18 path_to_insert
19 path_to_check
20 found
21 i j
22 ;
23
24
25 /* Make sure the mode parameter is set */
26 %if %sysevalf(%superq(mode) =, boolean) %then %do;
27 %put WARNING: input parameter MODE is missing. Setting MODE = insert;
28 %let mode = insert;
29 %end;
30 %else %do;
31 %let mode = %lowcase(&mode.);
32 /* Make sure the MODE parameter is one of the following: insert/append/set */
33 %if(not %sysfunc(prxmatch(/^(insert|append|set)$/i, &mode.))) %then %do;
34 %put ERROR: invalid parameter MODE = &mode.. Accepted values: insert/append/set;
35 %return;
36 %end;
37 %end;
38
39
40 /* Make sure the limit is set */
41 %if %sysevalf(%superq(limit) =, boolean) %then
42 %let limit = 0;
43
44 /* Make sure the force_flg is set */
45 %if %sysevalf(%superq(force_flg) =, boolean) %then
46 %let force_flg = N;
47 %else
48 %let force_flg = %upcase(&force_flg.);
49
50 %if %sysevalf(%superq(fa_path) =, boolean) %then %do;
51 /* Get the list of IRM federated areas matching the specified value */
52 %irm_get_swc_property(swc_name = IRM Mid-Tier Server
53 , property = com.sas.solutions.risk.irm.fa.(?!readonly.)&fa_id.
54 , debug = true
55 , outvar = swc_property_value
56 , out_ds = irm_federated_areas
57 , pattern_match_flg = Y
58 );
59
60 /* Sort in descending order */
61 proc sort data = irm_federated_areas;
62 by descending property_name;
63 run;
64
65 /* Load the list of FAs into macro variable array */
66 %let TotFas = 0;
67 data _null_;
68 set
69 irm_federated_areas
70 %if(&limit. > 0) %then %do;
71 (obs = &limit.)
72 %end;
73 end = last
74 ;
75 call symputx(cats("fa_path_", put(_N_, 8.)), cats(property_value, "/source/sas/ucmacros"), "L");
76 if last then
77 call symputx("TotFas", _N_, "L");
78 run;
79 %end;
80 %else %do;
81 %let TotFas = %sysfunc(countw(%superq(fa_path), %str(,)));
82 %do i = 1 %to &TotFas.;
83 %local fa_path_&i.;
84 %let fa_path_&i. = %scan(%superq(fa_path), &i., %str(,));
85 %end;
86 %end;
87
88 %if %sysevalf(%superq(outvar_prefix) ne, boolean) %then %do;
89 %global &outvar_prefix._count;
90 %let &outvar_prefix._count = &TotFas.;
91 %do i = 1 %to &TotFas.;
92 %global &outvar_prefix._&i.;
93 %let &outvar_prefix._&i. = "&&fa_path_&i..";
94 %end;
95 %end;
96
97 /* Process the SASAUTOS and split it into the individual entries */
98 %let TotPaths = 0;
99 data _null_;
100 length
101 sasautos $32000.
102 path $32000.
103 ;
104 /* Regex to remove any brackets: ("path1" ('path2') ... SASAUTOS) --> "path1" 'path2' ... SASAUTOS */
105 rx1 = prxparse("s/[()]/ /");
106 /* Regex to convert double to single quotes: "path1" 'path2' ... SASAUTOS --> 'path1' 'path2' ... SASAUTOS */
107 rx2 = prxparse("s/[""]/'/");
108 /* Regex to match a quoted path or a fileref (wingle word): 'foo/bar' or fref1 */
109 rx = prxparse("/(['][^']+['])|(\w+)/");
110 /* Get the current sasautos */
111 sasautos = getoption("sasautos");
112 /* Remove brackets */
113 sasautos = prxchange(rx1, -1, sasautos);
114 /* Convert double quotes to single quotes */
115 sasautos = prxchange(rx2, -1, sasautos);
116
117 /* Start scanning */
118 start = 1;
119 stop = length(sasautos);
120 call prxnext(rx, start, stop, sasautos, position, len);
121 i = 0;
122 do while (position > 0);
123 i + 1;
124 /* Extract the current path */
125 path = substr(sasautos, position, len);
126 /* Save the path to a macro variable */
127 call symputx(cats("sasautos_path_", put(i, 8.)), path, "L");
128 /* Look for the next match */
129 call prxnext(rx, start, stop, sasautos, position, len);
130 end;
131
132 call symputx("TotPaths", i, "L");
133 run;
134
135
136 /* Pre-processing required to make sure we don't insert paths that are already there */
137 %let TotFaInsert = 0;
138 %do i = 1 %to &TotFas.;
139 %let path_to_insert = %sysfunc(prxchange(s/[\\]/\//i, -1, %superq(fa_path_&i.)));
140 %let found = N;
141 %if(&force_flg. = N and &mode. ne set) %then %do;
142 /* Check if the path to be inserted is already in the sasautos */
143 %do j = 1 %to &TotPaths.;
144 %let path_to_check = %sysfunc(prxchange(s/[\\]/\//i, -1, %superq(sasautos_path_&j.)));
145 %let path_to_check = %sysfunc(prxchange(s/['']//i, -1, %superq(path_to_check)));
146 %if(%bquote(&path_to_insert.) = %bquote(&path_to_check.)) %then
147 %let found = Y;
148 %end;
149 %end;
150 %if(&found. = N) %then %do;
151 %let TotFaInsert = %eval(&TotFaInsert. + 1);
152 %local fa_insert_path_&TotFaInsert.;
153 %let fa_insert_path_&TotFaInsert. = &&fa_path_&i..;
154 %end;
155 %end;
156
157
158 /* Add all the FAs to the sasautos */
159 %if(&TotFaInsert. > 0) %then %do;
160
161 /* Use standard insert/append option */
162 %if (%sysfunc(prxmatch(/^(insert|append)$/i, &mode.))
163 and %sysevalf(%superq(insert_before) =, boolean)
164 and %sysevalf(%superq(insert_after) =, boolean)
165 ) %then %do;
166 option
167 &mode. = (sasautos = (
168 %do i = 1 %to &TotFaInsert.;
169 "&&fa_insert_path_&i.."
170 %end;
171 )
172 )
173 ;
174
175 %end;
176 %else %do;
177
178 /* Make sure there insert_before/after parameters contain a forward slash at the end */
179 %let prx_before = %sysfunc(prxchange(s/([\\\/][^\\\/])[\\\/]?$/$1\//i, -1, &insert_before.));
180 %let prx_before = %sysfunc(prxchange(s/[\\\/]/\\\//i, -1, &prx_before.));
181
182 %let prx_after = %sysfunc(prxchange(s/([\\\/][^\\\/])[\\\/]?$/$1\//i, -1, &insert_after.));
183 %let prx_after = %sysfunc(prxchange(s/[\\\/]/\\\//i, -1, &prx_after.));
184
185 /* Set the new SASAUTOS */
186 option
187 sasautos = (
188
189 /* Flag used to determine if we have inserted the new paths */
190 %let processed = N;
191
192 /* Loop through all pre-existing sasautos paths */
193 %do i = 1 %to &TotPaths.;
194 /* Set the current path */
195 %let path = &&sasautos_path_&i..;
196 /* Convert any backslash into a forward slash */
197 %let fwd_path = %sysfunc(prxchange(s/\\/\//i, -1, &path.));
198 /* Remove single quotes */
199 %let fwd_path = %sysfunc(prxchange(s/['']//i, -1, &fwd_path.));
200
201 /* Check if we need to insert the paths before the specified value */
202 %if (&processed. = N and %sysevalf(%superq(insert_before) ne, boolean)) %then %do;
203 %if( (/* The current path is a fileref (single word) */
204 %sysfunc(prxmatch(/^\w+$/, &fwd_path.)) > 0
205 /* and we get a match (case insensitive) */
206 and %qlowcase(&insert_before.) = %qlowcase(&fwd_path.)
207 )
208 OR
209 (/* The current path is not a fileref */
210 %sysfunc(prxmatch(/^\w+$/, &fwd_path.)) = 0
211 /* We match the path */
212 and %sysfunc(prxmatch(/^&prx_before./, &fwd_path.)) > 0
213 )
214 ) %then %do;
215 /* Insert the requested paths */
216 %do j = 1 %to &TotFaInsert.;
217 "&&fa_insert_path_&j.."
218 %end;
219 /* Mark the fact that we have inserted the requested paths */
220 %let processed = Y;
221 %end;
222 %end;
223
224 /* Add the current path if we are not in SET mode */
225 %if(&mode. ne set) %then %do;
226 &path.
227 %end;
228
229 /* Check if we need to insert the paths after the specified value */
230 %if (&processed. = N and %sysevalf(%superq(insert_after) ne, boolean)) %then %do;
231 %if( (/* The current path is a fileref (single word) */
232 %sysfunc(prxmatch(/^\w+$/, &fwd_path.)) > 0
233 /* and we get a match (case insensitive) */
234 and %qlowcase(&insert_after.) = %qlowcase(&fwd_path.)
235 )
236 OR
237 (/* The current path is not a fileref */
238 %sysfunc(prxmatch(/^\w+$/, &fwd_path.)) = 0
239 /* We match the path */
240 and %sysfunc(prxmatch(/^&prx_after./, &fwd_path.)) > 0
241 )
242 ) %then %do;
243 /* Insert the requested paths */
244 %do j = 1 %to &TotFaInsert.;
245 "&&fa_insert_path_&j.."
246 %end;
247 /* Mark the fact that we have inserted the requested paths */
248 %let processed = Y;
249 %end;
250 %end;
251
252 %end; /* %do i = 1 %to &TotPaths.; */
253
254 /* Make sure we have inserted the path */
255 %if(&processed. = N) %then %do;
256 /* Insert the requested paths */
257 %do j = 1 %to &TotFaInsert.;
258 "&&fa_insert_path_&j.."
259 %end;
260 %end;
261 )
262 ;
263
264 %end;
265
266 %end; /* %if(&TotFaInsert. > 0) */
267%mend;