68%macro mp_filtercheck(inds,targetds=,outds=work.badrecords,abort=YES);
70%mp_abort(iftrue= (&syscc ne 0)
72 ,msg=%str(syscc=&syscc - on macro entry)
77%let vtype=%mf_getvartype(&inds,RAW_VALUE);
78%mp_abort(iftrue=(&abort=YES and &vtype ne C),
80 msg=%str(%str(ERR)OR: RAW_VALUE must be character)
82%
if &vtype ne C %then %
do;
83 %put &sysmacroname: RAW_VALUE must be character;
99 length reason_cd $4032 vtype vtype2 $1 vnum dsid 8 tmp $4000 re_temporal 8
101 drop tmp re_temporal vref;
104 if _n_=1 then re_temporal=prxparse(
"/^'[^']*'(dt|d|t)$/i");
107 if upcase(VARIABLE_NM) not in
108 (%upcase(%mf_getvarlist(&targetds,dlm=%str(,),quote=SINGLE)))
110 REASON_CD=
"Variable "!!cats(variable_nm)!!
" not in &targetds";
111 putlog REASON_CD= VARIABLE_NM=;
112 call symputx(
'reason_cd',reason_cd,
'l');
113 call symputx(
'nobs',_n_,
'l');
120 if _n_=1 then dsid=open(
"&targetds",
"i");
122 vnum=varnum(dsid,VARIABLE_NM);
125 REASON_CD=cats(
"Variable (",VARIABLE_NM,
") not found in &targetds");
126 putlog REASON_CD= dsid=;
127 call symputx(
'reason_cd',reason_cd,
'l');
128 call symputx(
'nobs',_n_,
'l');
133 else vtype=vartype(dsid,vnum);
136 REASON_CD=cats(
"Could not open &targetds");
137 putlog REASON_CD= dsid=;
138 call symputx(
'reason_cd',reason_cd,
'l');
139 call symputx(
'nobs',_n_,
'l');
145 if GROUP_LOGIC not in (
'AND',
'OR') then do;
146 REASON_CD='GROUP_LOGIC should be AND/OR, not:'!!cats(GROUP_LOGIC);
147 putlog REASON_CD= GROUP_LOGIC=;
148 call symputx('reason_cd',reason_cd,
'l');
149 call symputx('nobs',_n_,
'l');
152 if SUBGROUP_LOGIC not in ('AND
','OR') then do;
153 REASON_CD='SUBGROUP_LOGIC should be AND/OR, not:'!!cats(SUBGROUP_LOGIC);
154 putlog REASON_CD= SUBGROUP_LOGIC=;
155 call symputx('reason_cd',reason_cd,
'l');
156 call symputx('nobs',_n_,
'l');
159 if mod(SUBGROUP_ID,1) ne 0 then do;
160 REASON_CD='SUBGROUP_ID should be integer, not '!!cats(subgroup_id);
161 putlog REASON_CD= SUBGROUP_ID=;
162 call symputx('reason_cd',reason_cd,
'l');
163 call symputx('nobs',_n_,
'l');
166 if OPERATOR_NM not in
167 (
'=',
'>',
'<','<=
','>=
','NE
','GE
','LE
','BETWEEN
','IN
','NOT IN
','CONTAINS'
170 REASON_CD='Invalid OPERATOR_NM: '!!cats(OPERATOR_NM);
171 putlog REASON_CD= OPERATOR_NM=;
172 call symputx('reason_cd',reason_cd,
'l');
173 call symputx('nobs',_n_,
'l');
181 if vtype=
'N' & OPERATOR_NM in ('CONTAINS
','=:
','^=:') then do;
182 vref=cats(
"&targetds",
'.',VARIABLE_NM);
183 REASON_CD=catx(
' ',OPERATOR_NM,'is only valid for character'
184 ,'variables -',vref,'is numeric');
185 putlog REASON_CD= OPERATOR_NM=;
186 call symputx('reason_cd',reason_cd,
'l');
187 call symputx('nobs',_n_,
'l');
195 if vtype=
'C' & OPERATOR_NM='CONTAINS'
196 & subpad(strip(raw_value),1,1) not in (
'"',
"'")
198 vref=cats(
"&targetds",
'.',VARIABLE_NM);
201 if prxmatch('/^[a-z_][a-z0-9_]*$/i',strip(raw_value))>0 then do;
202 vnum=varnum(dsid,strip(raw_value));
206 vtype2=vartype(dsid,vnum);
207 if vtype2=
'C' then return;
208 REASON_CD=catx(
' ',
"Compared Type ("!!vtype2!!
") is not (C) -"
209 ,vref,'CONTAINS',cats(raw_value));
211 else REASON_CD=catx(
' ','CONTAINS requires a quoted value or a character'
212 ,'variable -',vref,'CONTAINS',cats(raw_value));
213 putlog REASON_CD= OPERATOR_NM=;
214 call symputx('reason_cd',reason_cd,
'l');
215 call symputx('nobs',_n_,
'l');
221 if vtype=
'N' & OPERATOR_NM in (
'=',
'>',
'<','<=
','>=
','NE
','GE
','LE') then do;
222 if cats(upcase(raw_value)) in (
223 '.','.A
','.B
','.C
','.D
','.E
','.F
','.G
','.H
','.I
','.J
','.K
','.L
','.M
','.N'
224 '.N
','.O
','.P
','.Q
','.R
','.S
','.T
','.U
','.V
','.W
','.X
','.Y
','.Z
','._'
230 else if subpad(upcase(raw_value),1,1) in (
231 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N'
232 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'_'
236 vnum=varnum(dsid,subpad(raw_value,1,32));
239 vtype2=vartype(dsid,vnum);
241 if vtype2=vtype then do;
246 REASON_CD=cats(
"Compared Type (",vtype2,
") is not (",vtype,
")");
247 putlog REASON_CD= dsid=;
248 call symputx('reason_cd',reason_cd,
'l');
249 call symputx('nobs',_n_,
'l');
258 if vtype=
'N' and prxmatch(re_temporal,cats(raw_value))>0 then return;
261 if OPERATOR_NM in ('IN
','NOT IN
','BETWEEN') then do;
262 if OPERATOR_NM='BETWEEN' then raw_value1=tranwrd(raw_value,' AND
',',');
264 if substr(raw_value,1,1) ne
'('
265 or substr(cats(reverse(raw_value)),1,1) ne
')'
267 REASON_CD='Missing start/end bracket in RAW_VALUE';
268 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
269 call symputx('reason_cd',reason_cd,
'l');
270 call symputx('nobs',_n_,
'l');
273 else raw_value1=substr(raw_value,2,max(length(raw_value)-2,0));
276 if vtype=
'N' then do i=1 to countc(raw_value1,
',')+1;
277 tmp=scan(raw_value1,i,
',');
278 if cats(tmp) ne
'.' and input(tmp, ?? 8.) eq . then do;
280 if prxmatch(re_temporal,cats(tmp))=0 then do;
281 if OPERATOR_NM ='BETWEEN' and subpad(upcase(tmp),1,1) in (
282 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N'
283 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'_'
288 vnum=varnum(dsid,subpad(tmp,1,32));
291 vtype2=vartype(dsid,vnum);
293 if vtype2 ne vtype then do;
294 REASON_CD=cats(
"Compared Type (",vtype2,
") is not (",vtype,
")");
295 putlog REASON_CD= dsid=;
296 call symputx('reason_cd',reason_cd,
'l');
297 call symputx('nobs',_n_,
'l');
303 REASON_CD='Non Numeric value provided';
304 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
305 call symputx('reason_cd',reason_cd,
'l');
306 call symputx('nobs',_n_,
'l');
311 REASON_CD='Non Numeric value provided';
312 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
313 call symputx('reason_cd',reason_cd,
'l');
314 call symputx('nobs',_n_,
'l');
323 if vtype=
'N' then return;
325 else raw_value1=raw_value;
328 raw_value1=tranwrd(raw_value1,
"''",'');
331 raw_value2=raw_value1;
332 regex = prxparse(
"s/(\').*?(\')//");
333 call prxchange(regex,-1,raw_value2);
336 raw_value3=compress(raw_value2,',.');
339 if notdigit(compress(raw_value3,
' '))>0 then do;
340 if vtype=
'C' and subpad(upcase(raw_value),1,1) in (
341 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N'
342 'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'_'
346 vnum=varnum(dsid,subpad(raw_value,1,32));
349 vtype2=vartype(dsid,vnum);
351 if vtype2=vtype then do;
356 REASON_CD=cats(
"Compared Char Type (",vtype2,
") is not (",vtype,
")");
357 putlog REASON_CD= dsid=;
358 call symputx('reason_cd',reason_cd,
'l');
359 call symputx('nobs',_n_,
'l');
366 putlog raw_value3= $hex32.;
367 REASON_CD=cats('Invalid RAW_VALUE:',raw_value);
369 call symputx('reason_cd',reason_cd,
'l');
370 call symputx('nobs',_n_,
'l');
375 if last then rc=close(dsid);
384%mp_abort(iftrue=(&abort=YES and &nobs>0),
386 msg=%str(Data issue: %superq(reason_cd))
389%if &nobs>0 %then %do;
399%let fref1=%mf_getuniquefileref();
400%mp_filtergenerate(&inds,outref=&fref1)
403%mp_filtervalidate(&fref1,&targetds,outds=&outds,abort=&abort)