65%macro mp_filtercheck(inds,targetds=,outds=work.badrecords,abort=YES);
67%mp_abort(iftrue= (&syscc ne 0)
69 ,msg=%str(syscc=&syscc - on macro entry)
74%let vtype=%mf_getvartype(&inds,RAW_VALUE);
75%mp_abort(iftrue=(&abort=YES and &vtype ne C),
77 msg=%str(%str(ERR)OR: RAW_VALUE must be character)
79%if &vtype ne C %then %do;
80 %put &sysmacroname: RAW_VALUE must be character;
96 length reason_cd $4032 vtype vtype2 $1 vnum dsid 8 tmp $4000;
100 if upcase(VARIABLE_NM) not in
101 (%upcase(%mf_getvarlist(&targetds,dlm=%str(,),quote=SINGLE)))
103 REASON_CD=
"Variable "!!cats(variable_nm)!!
" not in &targetds";
104 putlog REASON_CD= VARIABLE_NM=;
105 call symputx(
'reason_cd',reason_cd,
'l');
106 call symputx(
'nobs',_n_,
'l');
113 if _n_=1 then dsid=open(
"&targetds",
"i");
115 vnum=varnum(dsid,VARIABLE_NM);
118 REASON_CD=cats(
"Variable (",VARIABLE_NM,
") not found in &targetds");
119 putlog REASON_CD= dsid=;
120 call symputx(
'reason_cd',reason_cd,
'l');
121 call symputx(
'nobs',_n_,
'l');
126 else vtype=vartype(dsid,vnum);
129 REASON_CD=cats(
"Could not open &targetds");
130 putlog REASON_CD= dsid=;
131 call symputx(
'reason_cd',reason_cd,
'l');
132 call symputx(
'nobs',_n_,
'l');
138 if GROUP_LOGIC not in (
'AND',
'OR') then do;
139 REASON_CD='GROUP_LOGIC should be AND/OR, not:'!!cats(GROUP_LOGIC);
140 putlog REASON_CD= GROUP_LOGIC=;
141 call symputx('reason_cd',reason_cd,'l');
142 call symputx('nobs',_n_,'l');
145 if SUBGROUP_LOGIC not in ('AND','OR') then do;
146 REASON_CD='SUBGROUP_LOGIC should be AND/OR, not:'!!cats(SUBGROUP_LOGIC);
147 putlog REASON_CD= SUBGROUP_LOGIC=;
148 call symputx('reason_cd',reason_cd,'l');
149 call symputx('nobs',_n_,'l');
152 if mod(SUBGROUP_ID,1) ne 0 then do;
153 REASON_CD='SUBGROUP_ID should be integer, not '!!cats(subgroup_id);
154 putlog REASON_CD= SUBGROUP_ID=;
155 call symputx('reason_cd',reason_cd,'l');
156 call symputx('nobs',_n_,'l');
159 if OPERATOR_NM not in
160 ('=','>','<','<=','>=','NE','GE','LE','BETWEEN','IN','NOT IN','CONTAINS')
162 REASON_CD='Invalid OPERATOR_NM: '!!cats(OPERATOR_NM);
163 putlog REASON_CD= OPERATOR_NM=;
164 call symputx('reason_cd',reason_cd,'l');
165 call symputx('nobs',_n_,'l');
170 if vtype='N' & OPERATOR_NM in ('=','>','<','<=','>=','NE','GE','LE') then do;
171 if cats(upcase(raw_value)) in (
172 '.','.A','.B','.C','.D','.E','.F','.G','.H','.I','.J','.K','.L','.M','.N'
173 '.N','.O','.P','.Q','.R','.S','.T','.U','.V','.W','.X','.Y','.Z','._'
179 else if subpad(upcase(raw_value),1,1) in (
180 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
181 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
185 vnum=varnum(dsid,subpad(raw_value,1,32));
188 vtype2=vartype(dsid,vnum);
190 if vtype2=vtype then do;
195 REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
196 putlog REASON_CD= dsid=;
197 call symputx('reason_cd',reason_cd,'l');
198 call symputx('nobs',_n_,'l');
207 if OPERATOR_NM in ('IN','NOT IN','BETWEEN') then do;
208 if OPERATOR_NM='BETWEEN' then raw_value1=tranwrd(raw_value,' AND ',',');
210 if substr(raw_value,1,1) ne '('
211 or substr(cats(reverse(raw_value)),1,1) ne ')'
213 REASON_CD='Missing start/end bracket in RAW_VALUE';
214 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
215 call symputx('reason_cd',reason_cd,'l');
216 call symputx('nobs',_n_,'l');
219 else raw_value1=substr(raw_value,2,max(length(raw_value)-2,0));
222 if vtype='N' then do i=1 to countc(raw_value1, ',')+1;
223 tmp=scan(raw_value1,i,',');
224 if cats(tmp) ne '.' and input(tmp, ?? 8.) eq . then do;
225 if OPERATOR_NM ='BETWEEN' and subpad(upcase(tmp),1,1) in (
226 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
227 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
232 vnum=varnum(dsid,subpad(tmp,1,32));
235 vtype2=vartype(dsid,vnum);
237 if vtype2=vtype then do;
242 REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
243 putlog REASON_CD= dsid=;
244 call symputx('reason_cd',reason_cd,'l');
245 call symputx('nobs',_n_,'l');
251 REASON_CD='Non Numeric value provided';
252 putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
253 call symputx('reason_cd',reason_cd,'l');
254 call symputx('nobs',_n_,'l');
260 else raw_value1=raw_value;
263 raw_value1=tranwrd(raw_value1,"''",'');
266 raw_value2=raw_value1;
267 regex = prxparse("s/(\').*?(\')
268 call prxchange(regex,-1,raw_value2);
271 raw_value3=compress(raw_value2,',.');
274 if notdigit(compress(raw_value3,' '))>0 then do;
275 if vtype='C' and subpad(upcase(raw_value),1,1) in (
276 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
277 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
281 vnum=varnum(dsid,subpad(raw_value,1,32));
284 vtype2=vartype(dsid,vnum);
286 if vtype2=vtype then do;
291 REASON_CD=cats("Compared Char Type (",vtype2,") is not (",vtype,")");
292 putlog REASON_CD= dsid=;
293 call symputx('reason_cd',reason_cd,'l');
294 call symputx('nobs',_n_,'l');
301 putlog raw_value3= $hex32.;
302 REASON_CD=cats('Invalid RAW_VALUE:',raw_value);
304 call symputx('reason_cd',reason_cd,'l');
305 call symputx('nobs',_n_,'l');
310 if last then rc=close(dsid);
319%mp_abort(iftrue=(&abort=YES and &nobs>0),
321 msg=%str(Data issue: %superq(reason_cd))
324%if &nobs>0 %then %do;
334%let fref1=%mf_getuniquefileref();
335%mp_filtergenerate(&inds,outref=&fref1)
338%mp_filtervalidate(&fref1,&targetds,outds=&outds,abort=&abort)