In the dataset shown below, why is the rskgrp showing 6?instead of 12
PROC FORMAT;
VALUE WEIGHT
0.000-0.249 = " 1"
0.250-0.499 = " 2"
0.500-0.749 = " 3"
0.750-0.999 = " 4"
1.000-1.249 = " 5"
1.250-1.499 = " 6"
1.500-1.999 = " 7"
2.000-2.499 = " 8"
2.500-2.999 = " 9"
3.000-3.999 = "10"
4.000-4.999 = "11"
5.000-5.999 = "12"
6.000-HIGH = "13"
;
RUN;
data _sk;
totalwt=5.9991;
RISKGRP=PUT(TOTALWT,WEIGHT.);
run;
SASPhile,
The value you have selected, 5.9991, is not defined within the format. So expressing it as "12" was never an option. Therefore, the PUT function returns the actual value (5.9991), but uses the width of 2 to express that value (since 2 is the width of the WEIGHT. format).
When you get into some of the intricacies, there is a FUZZ factor available, but it is usually set much smaller than 0.0001. You would be better advised to define your format so that there are no gaps. Consider whether this would be appropriate:
5 - < 6 = "12"
Good luck.
Your ranges are not continuous. Either fix your formats like this:
PROC FORMAT;
VALUE WEIGHT
0.000-<0.25 = " 1"
0.250-<0.5 = " 2"
0.500-<0.75 = " 3"
0.750-<1 = " 4"
1.000-<1.25 = " 5"
1.250-<1.5 = " 6"
1.500-<2 = " 7"
2.000-<2.5 = " 8"
2.500-<3 = " 9"
3.000-<4 = "10"
4.000-<5 = "11"
5.000-<6 = "12"
6.000-HIGH = "13"
;
RUN;
...or round the value you want to format to 3 decimals before you apply the format like this:
totalwt=round( 5.9991, .001 );
Astounding has given you a answer, you need an option for your format.
PROC FORMAT;
VALUE WEIGHT(fuzz=.001)
0.000-0.249 = " 1"
0.250-0.499 = " 2"
0.500-0.749 = " 3"
0.750-0.999 = " 4"
1.000-1.249 = " 5"
1.250-1.499 = " 6"
1.500-1.999 = " 7"
2.000-2.499 = " 8"
2.500-2.999 = " 9"
3.000-3.999 = "10"
4.000-4.999 = "11"
5.000-5.999 = "12"
6.000-HIGH = "13"
;
RUN;
data _sk;
totalwt=5.9991;
RISKGRP=PUT(TOTALWT,WEIGHT.);
run;
Ksharp
Alternatively you can increase the decimal portion from "0.999" to "0.9999". i executed the code below in SAS and it worked.
PROC FORMAT;
VALUE WEIGHT
0.000-0.2499 = " 1"
0.250-0.4999 = " 2"
0.500-0.7499 = " 3"
0.750-0.9999 = " 4"
1.000-1.2499 = " 5"
1.250-1.4999 = " 6"
1.500-1.9999 = " 7"
2.000-2.4999 = " 8"
2.500-2.9999 = " 9"
3.000-3.9999 = "10"
4.000-4.9999 = "11"
5.000-5.9999 = "12"
6.000-HIGH = "13"
;
RUN;
data _sk;
totalwt=5.9991;
RISKGRP=PUT(TOTALWT,WEIGHT.);
put totalwt= riskgrp=;
run;
Output:
totalwt=5.9991 riskgrp=12
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!
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.