BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
_maldini_
Barite | Level 11

How do I capture all values of a continuous measure using formats?

 

For example: yrs_monthly_use = 5.3 (5.3 years of monthly use)

 

VALUE 
	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-10 = "5-10 yrs"
			10-high = "> 10 yrs";

 

With the syntax above, 5.3 will end up in the 2nd category. Great.

Where does 10 end up? Also, in the 2nd category?

How do I modify the syntax so that the third category captures any value greater than 10?

 

I tried the following, but the label for the 2nd category becomes "5-10 yrs >":

	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-10 = "5-10 yrs"
			>10-high = "> 10 yrs";

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The extra > comes from the ">10-high" portion, not the specification of the range. 

 

You have the somewhat right idea, but you need to include the <  symbol in between the values and it means include the end points. 

 

proc format;
values	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-<10 = "5-10 yrs"
			10-high = "> 10 yrs";
			
run;

data demo;
do i=0 to 12 by 0.5;
month = put(i, yrs_monthly_usefmt.);
output;
end;
run;

proc print data=demo;
run;

I believe by default the end point is included in the interval. But you can modify that with the < symbol. Try playing around with including it inside the ranges. 

 

This is a good one to test for example:

 

proc format;
value	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5<-<10 = "5-10 yrs"
			10-high = "> 10 yrs";
			
run;

5 doesn't get included in any range here, so it doesn't get formatted at all 🙂

 


@_maldini_ wrote:

How do I capture all values of a continuous measure using formats?

 

For example: yrs_monthly_use = 5.3 (5.3 years of monthly use)

 

VALUE 
	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-10 = "5-10 yrs"
			10-high = "> 10 yrs";

 

With the syntax above, 5.3 will end up in the 2nd category. Great.

Where does 10 end up? Also, in the 2nd category?

How do I modify the syntax so that the third category captures any value greater than 10?

 

I tried the following, but the label for the 2nd category becomes "5-10 yrs >":

	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-10 = "5-10 yrs"
			>10-high = "> 10 yrs";

Thanks.


 

Spoiler
This is the format you want most likely:



proc format;
value yrs_monthly_usefmt
low-<5 = "< 5 yrs"
5-10 = "5-10 yrs"
10<-high = "> 10 yrs";

run;

View solution in original post

2 REPLIES 2
Reeza
Super User

The extra > comes from the ">10-high" portion, not the specification of the range. 

 

You have the somewhat right idea, but you need to include the <  symbol in between the values and it means include the end points. 

 

proc format;
values	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-<10 = "5-10 yrs"
			10-high = "> 10 yrs";
			
run;

data demo;
do i=0 to 12 by 0.5;
month = put(i, yrs_monthly_usefmt.);
output;
end;
run;

proc print data=demo;
run;

I believe by default the end point is included in the interval. But you can modify that with the < symbol. Try playing around with including it inside the ranges. 

 

This is a good one to test for example:

 

proc format;
value	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5<-<10 = "5-10 yrs"
			10-high = "> 10 yrs";
			
run;

5 doesn't get included in any range here, so it doesn't get formatted at all 🙂

 


@_maldini_ wrote:

How do I capture all values of a continuous measure using formats?

 

For example: yrs_monthly_use = 5.3 (5.3 years of monthly use)

 

VALUE 
	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-10 = "5-10 yrs"
			10-high = "> 10 yrs";

 

With the syntax above, 5.3 will end up in the 2nd category. Great.

Where does 10 end up? Also, in the 2nd category?

How do I modify the syntax so that the third category captures any value greater than 10?

 

I tried the following, but the label for the 2nd category becomes "5-10 yrs >":

	yrs_monthly_usefmt
			low-<5 = "< 5 yrs"
			5-10 = "5-10 yrs"
			>10-high = "> 10 yrs";

Thanks.


 

Spoiler
This is the format you want most likely:



proc format;
value yrs_monthly_usefmt
low-<5 = "< 5 yrs"
5-10 = "5-10 yrs"
10<-high = "> 10 yrs";

run;
Tom
Super User Tom
Super User

It is not hard to run a little test to see what it does.

1733  data _null_;
1734    do yrs=1,5,7,10,12 ;
1735      put yrs= yrs yrs.;
1736    end;
1737  run;

yrs=1 < 5 yrs
yrs=5 5-10 yrs
yrs=7 5-10 yrs
yrs=10 5-10 yrs
yrs=12 > 10 yrs

If you want to exclude one of the boundaries from a range place a < on that side of the hyphen.

proc format;
  VALUE yrs
    low-<5 = "< 5 yrs"
    5-<10 = "5-10 yrs"
    10-high = "10+ yrs"
  ;
run;

Result

1745  data _null_;
1746    do yrs=1,5,7,10,12 ;
1747      put yrs= yrs yrs.;
1748    end;
1749  run;

yrs=1 < 5 yrs
yrs=5 5-10 yrs
yrs=7 5-10 yrs
yrs=10 10+ yrs
yrs=12 10+ yrs

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 437 views
  • 2 likes
  • 3 in conversation