Hi, I'm trying to understand the exact range for a format value statement.
This is my code:
data courses;
input exam;
datalines;
0.5
1
1.5
49.5
50
50.5
51
51.5
52
;
run;
proc format;
value score 1-50 = 'Fail'
51-100 = 'Pass';
run;
proc report data = courses nowd;
column exam;
define exam / display format = score.;
run;
The complied result is:
0.5 -> 0.5
1 -> fail
1.5 -> fail
49.5 -> fail
50 -> fail
50.5 -> 50.5
51 -> pass
51.5 -> pass
52 -> pass
Thus, it's not hard to conclude that the range '1-50' is identical to 1 <= somewhere <= 50,
in a similar vein, 51-100 can be interpreted as 51 <= somewhere <= 100
but, when I change the above program to this (second range was modified):
proc format;
value score 1-50 = 'Fail'
50-100 = 'Pass';
run;
while the first range covers the identical range (1 <= somewhere <= 50), the second one changes, covering: 50<somewhere <=100.
The second range does not cover 50.
Although this may be natural when ranges are specified consecutively and continuously, this is confusing.
Can anyone tell me why the complier interpretes this way?
@jimmychoi wrote:
Hi Tom, question was:
when format range is declared as 1-50, 51-100, then the value 50 is, of course, part of range 1-50.
Now, when format range is declared as 1-50, 50-100, then the value 50 is, part of range 1-50.
Why is that? Why not part of 50-100 range?
In previous versions of SAS that format with 50 in both ranges would have generated an error.
There are 2 characters involved with ranges: - < . - by itself includes the end values. If you use 50 <- 100 then you are using "greater than but not equal to 50 up to and including 100", 50 -< 100 is using "50 to but not including 100" and 50< - <100 is "between 50 and 100 excluding 100 and 50". This last might be of use if you want to assign something like: 100= 'Perfect'.
Your initial format did not assign formatted values to anything between 50 and 51. Perhaps you wanted
50<- 100.
I really don't understand the question.
Values that are not covered by any of the ranges in the format are displayed normally instead.
@jimmychoi wrote:
Hi Tom, question was:
when format range is declared as 1-50, 51-100, then the value 50 is, of course, part of range 1-50.
Now, when format range is declared as 1-50, 50-100, then the value 50 is, part of range 1-50.
Why is that? Why not part of 50-100 range?
Because that is how SAS designed it to behave. If you want to control which range the dividing value belongs to use the < symbol to exclude it from one of them.
@jimmychoi wrote:
Hi Tom, question was:
when format range is declared as 1-50, 51-100, then the value 50 is, of course, part of range 1-50.
Now, when format range is declared as 1-50, 50-100, then the value 50 is, part of range 1-50.
Why is that? Why not part of 50-100 range?
In previous versions of SAS that format with 50 in both ranges would have generated an error.
There are 2 characters involved with ranges: - < . - by itself includes the end values. If you use 50 <- 100 then you are using "greater than but not equal to 50 up to and including 100", 50 -< 100 is using "50 to but not including 100" and 50< - <100 is "between 50 and 100 excluding 100 and 50". This last might be of use if you want to assign something like: 100= 'Perfect'.
Your initial format did not assign formatted values to anything between 50 and 51. Perhaps you wanted
50<- 100.
That is the way sas do . If you want include 50 too, add an option.
proc format;
value score(multilabel) 1-50 = 'Fail'
50-100 = 'Pass';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: