SAS Helpful Hints
Range Checks
Here is a quick method to detect values out of range within a dataset
using arrays:
Data work.errors;
* variables to be checked;
Array checking age weight
height;
* lowest allowable values;
Array low{3} (21 90
48);
* highest allowable values;
Array high{3} (95 300
84);
Array erred{3} $6 ('Age'
'Weight' 'Height');
Set work.A;
Length flag $ 30;
flag=' ';
Do i=1 To Dim(checking);
If .Z<checking{i}<low{i}
or checking{i}>high{i} Then
flag=Compress(flag||'+'||erred{i});
End;
If flag^=' ' then output work.errors;
Run;
Results
| id |
flag |
age |
low1 |
high1 |
weight |
low2 |
high2 |
height |
low3 |
high3 |
| 22 |
+age |
18 |
21 |
95 |
120 |
90 |
300 |
72 |
48 |
84 |
| 23 |
+weight |
24 |
21 |
95 |
40 |
90 |
300 |
60 |
48 |
84 |
| 24 |
+height |
36 |
21 |
95 |
190 |
90 |
300 |
99 |
48 |
84 |
| 25 |
+age+weight |
14 |
21 |
95 |
320 |
90 |
300 |
66 |
48 |
84 |
Please send your comments and suggestions about this web page to A. Watts
(watts@bst.rochester.edu)
|