## Proc Format

Super Contributor
Posts: 713

# Proc Format

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;

Super User
Posts: 6,765

## Re: Proc Format

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.

Frequent Contributor
Posts: 103

## Re: Proc Format

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 );

Super User
Posts: 10,778

## Re: Proc Format

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

Posts: 1,147

## Re: Proc Format

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

Thanks,
Jag
Discussion stats
• 4 replies
• 290 views
• 4 likes
• 5 in conversation