I've created a format that assigns a State label to a pre-defined range of Start-End numeric postcodes.
i.e.
Start | End | State
2600 | 2618 | ACT
2900 | 2949 | ACT
4000 | 4899 | QLD
I want to add a piece of code to the format file that assigns it a label "Error" when the postcode falls outside of my range.
In a previous thread, someone suggested using the HLO solution but I have tried implementing it with mixed success.
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;
Oddly, only the Middling ranges BETWEEN Low-High that are correctly labelled Error and the ranges outside Low-High that are incorrectly labelled. (I would expect the opposite to be true but still not working the way I want)
For clarity this is what's happening from my same ruleset:
Pcode | ShouldReturn (Reason) | ActuallyReturns
2615 | ACT | ACT
2000 | Error (TooLow) | ACT
2700 | Error (Undefined range) | Error
5000 | Error (Too High) | QLD
I just want anything undefined to be called Error despite it being too low or too high. Please help!
Your logic is incomplete. You want to add three new records.
So you want logic like this: