BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jimmychoi
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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
Obsidian | Level 7
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?
Tom
Super User Tom
Super User

@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. 

http://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=proc&docsetTarget=n03qskwo...

ballardw
Super User

@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.

Ksharp
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 881 views
  • 1 like
  • 4 in conversation