BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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;

4 REPLIES 4
Astounding
PROC Star

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.

FloydNevseta
Pyrite | Level 9

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

Ksharp
Super User

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

Jagadishkatam
Amethyst | Level 16

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 876 views
  • 4 likes
  • 5 in conversation