67%macro mp_filtercheck(inds,targetds=,outds=work.badrecords,abort=YES);
69%mp_abort(iftrue= (&syscc ne 0)
71 ,msg=%str(syscc=&syscc - on macro entry)
76%let vtype=%mf_getvartype(&inds,RAW_VALUE);
77%mp_abort(iftrue=(&abort=YES and &vtype ne C),
79 msg=%str(%str(ERR)OR: RAW_VALUE must be character)
81%if &vtype ne C %then %do;
82 %put &sysmacroname: RAW_VALUE must be character;
98 length reason_cd $4032 vtype vtype2 $1 vnum dsid 8 tmp $4000 re_temporal 8;
102 if _n_=1 then re_temporal=prxparse(
"/^'[^']*'(dt|d|t)$/i");
105 if upcase(VARIABLE_NM) not in
106 (%upcase(%mf_getvarlist(&targetds,dlm=%str(,),quote=SINGLE)))
108 REASON_CD=
"Variable "!!cats(variable_nm)!!
" not in &targetds";
109 putlog REASON_CD= VARIABLE_NM=;
110 call symputx(
'reason_cd',reason_cd,
'l');
111 call symputx(
'nobs',_n_,
'l');
118 if _n_=1 then dsid=open(
"&targetds",
"i");
120 vnum=varnum(dsid,VARIABLE_NM);
123 REASON_CD=cats(
"Variable (",VARIABLE_NM,
") not found in &targetds");
124 putlog REASON_CD= dsid=;
125 call symputx(
'reason_cd',reason_cd,
'l');
126 call symputx(
'nobs',_n_,
'l');
131 else vtype=vartype(dsid,vnum);
134 REASON_CD=cats(
"Could not open &targetds");
135 putlog REASON_CD= dsid=;
136 call symputx(
'reason_cd',reason_cd,
'l');
137 call symputx(
'nobs',_n_,
'l');
143 if GROUP_LOGIC not in (
'AND',
'OR') then do;
144 REASON_CD='GROUP_LOGIC should be AND/OR, not:'!!cats(GROUP_LOGIC);
145 putlog REASON_CD= GROUP_LOGIC=;
146 call symputx('reason_cd',reason_cd,'l');
147 call symputx('nobs',_n_,'l');
150 if SUBGROUP_LOGIC not in ('AND','OR') then do;
151 REASON_CD='SUBGROUP_LOGIC should be AND/OR, not:'!!cats(SUBGROUP_LOGIC);
152 putlog REASON_CD= SUBGROUP_LOGIC=;
153 call symputx('reason_cd',reason_cd,'l');
154 call symputx('nobs',_n_,'l');
157 if mod(SUBGROUP_ID,1) ne 0 then do;
158 REASON_CD='SUBGROUP_ID should be integer, not '!!cats(subgroup_id);
159 putlog REASON_CD= SUBGROUP_ID=;
160 call symputx('reason_cd',reason_cd,'l');
161 call symputx('nobs',_n_,'l');
164 if OPERATOR_NM not in
165 ('=','>','<','<=','>=','NE','GE','LE','BETWEEN','IN','NOT IN','CONTAINS')
167 REASON_CD='Invalid OPERATOR_NM: '!!cats(OPERATOR_NM);
168 putlog REASON_CD= OPERATOR_NM=;
169 call symputx('reason_cd',reason_cd,'l');
170 call symputx('nobs',_n_,'l');
175 if vtype='N' & OPERATOR_NM in ('=','>','<','<=','>=','NE','GE','LE') then do;
176 if cats(upcase(raw_value)) in (
177 '.','.A','.B','.C','.D','.E','.F','.G','.H','.I','.J','.K','.L','.M','.N'
178 '.N','.O','.P','.Q','.R','.S','.T','.U','.V','.W','.X','.Y','.Z','._'
184 else if subpad(upcase(raw_value),1,1) in (
185 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
186 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
190 vnum=varnum(dsid,subpad(raw_value,1,32));
193 vtype2=vartype(dsid,vnum);
195 if vtype2=vtype then do;
200 REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
201 putlog REASON_CD= dsid=;
202 call symputx('reason_cd',reason_cd,'l');
203 call symputx('nobs',_n_,'l');
212 if vtype='N' and prxmatch(re_temporal,cats(raw_value))>0 then return;
215 if OPERATOR_NM in ('IN','NOT IN','BETWEEN') then do;
216 if OPERATOR_NM='BETWEEN' then raw_value1=tranwrd(raw_value,' AND ',',');
218 if substr(raw_value,1,1) ne '('
219 or substr(cats(reverse(raw_value)),1,1) ne ')'
221 REASON_CD='Missing start/end bracket in RAW_VALUE';
222 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
223 call symputx('reason_cd',reason_cd,'l');
224 call symputx('nobs',_n_,'l');
227 else raw_value1=substr(raw_value,2,max(length(raw_value)-2,0));
230 if vtype='N' then do i=1 to countc(raw_value1, ',')+1;
231 tmp=scan(raw_value1,i,',');
232 if cats(tmp) ne '.' and input(tmp, ?? 8.) eq . then do;
234 if prxmatch(re_temporal,cats(tmp))=0 then do;
235 if OPERATOR_NM ='BETWEEN' and subpad(upcase(tmp),1,1) in (
236 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
237 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
242 vnum=varnum(dsid,subpad(tmp,1,32));
245 vtype2=vartype(dsid,vnum);
247 if vtype2 ne vtype then do;
248 REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
249 putlog REASON_CD= dsid=;
250 call symputx('reason_cd',reason_cd,'l');
251 call symputx('nobs',_n_,'l');
257 REASON_CD='Non Numeric value provided';
258 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
259 call symputx('reason_cd',reason_cd,'l');
260 call symputx('nobs',_n_,'l');
265 REASON_CD='Non Numeric value provided';
266 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
267 call symputx('reason_cd',reason_cd,'l');
268 call symputx('nobs',_n_,'l');
277 if vtype='N' then return;
279 else raw_value1=raw_value;
282 raw_value1=tranwrd(raw_value1,"''",'');
285 raw_value2=raw_value1;
286 regex = prxparse("s/(\').*?(\')
287 call prxchange(regex,-1,raw_value2);
290 raw_value3=compress(raw_value2,',.');
293 if notdigit(compress(raw_value3,' '))>0 then do;
294 if vtype='C' and subpad(upcase(raw_value),1,1) in (
295 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
296 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
300 vnum=varnum(dsid,subpad(raw_value,1,32));
303 vtype2=vartype(dsid,vnum);
305 if vtype2=vtype then do;
310 REASON_CD=cats("Compared Char Type (",vtype2,") is not (",vtype,")");
311 putlog REASON_CD= dsid=;
312 call symputx('reason_cd',reason_cd,'l');
313 call symputx('nobs',_n_,'l');
320 putlog raw_value3= $hex32.;
321 REASON_CD=cats('Invalid RAW_VALUE:',raw_value);
323 call symputx('reason_cd',reason_cd,'l');
324 call symputx('nobs',_n_,'l');
329 if last then rc=close(dsid);
338%mp_abort(iftrue=(&abort=YES and &nobs>0),
340 msg=%str(Data issue: %superq(reason_cd))
343%if &nobs>0 %then %do;
353%let fref1=%mf_getuniquefileref();
354%mp_filtergenerate(&inds,outref=&fref1)
357%mp_filtervalidate(&fref1,&targetds,outds=&outds,abort=&abort)