You want to be extremely cautious with < or > comparisons involving character values that look like numbers.
Character comparisons are done left to right, first character of one value compared to the first character of the second, then the second character and so on. The comparison will stop when the first characters are unequal and use the result to that point
So when everything has exactly the same length and structure, such as hyphens or other punctuation, the results for what you show makes sense.
However when you get to different length character values things are very likely not to be what you might want.
Data example;
a= '111';
b= '20';
c= ' 45';
if a < b then put "A < B";
else put "A not < B";
if c < b then put "C < B";
else put "C not < B";
if a > C then put "A > C";
else put "A not > C";
run;
Why is '111' < '20'? Because the first character comparison, '1' and '2' the '1' is less than '2'.
Similar when the space in '045' is compared to the two in '20': space is less than 2 so the result is less.
For a great deal of things it is better off to have dates, times or datetime values as SAS date, time or datetime valued numeric values with an appropriate format. Then you can determine things like the number of days between two dates or increment values by some specified interval. Plus just changing the format can create different groups for analysis, graphing or report categories without having to modify the data.
... View more