我创建了一种格式,将状态标签分配给预定义的起始-结束数字邮政编码范围。
i.e.
Start | End | State
2600 | 2618 | ACT
2900 | 2949 | ACT
4000 | 4899 | QLD
我想在格式文件中添加一段代码,当邮政编码超出我的范围时,它会为其分配一个标签“错误”。
在之前的帖子中,有人建议使用 HLO 解决方案,但我尝试实现它的成功率参差不齐。
rsubmit;
data Fmt_State;
set State end=eof;
retain type 'n';
fmtname = 'category';
start = pcode_fr;
end = pcode_to;
label = State;
* For the first observation, assign the ‘LOW’ keyword;
if _n_ eq 1 then HLO='L';
if eof then do;
*** For the last observation, assign the ‘HIGH’ keyword and output;
HLO='H';
output;
*Define an 'Other' range that is outside the bounds of LOW and HIGH;
HLO='O';
label = "Error";
output;
end;
else output;
run;
endrsubmit;
奇怪的是,只有低-高之间的中间范围被正确标记为错误,而低-高之外的范围被错误标记。(我希望相反的情况是正确的,但仍然不能按照我想要的方式工作)
为清楚起见,这是我的同一个规则集中发生的事情:
Pcode | ShouldReturn (Reason) | ActuallyReturns
2615 | ACT | ACT
2000 | Error (TooLow) | ACT
2700 | Error (Undefined range) | Error
5000 | Error (Too High) | QLD
我只想将任何未定义的东西称为错误,尽管它太低或太高。请帮忙!