Solved
Contributor
Posts: 35

# Negative values in proc format

Dear All,

I'm trying to create a format which includes negative values. I have tried with and without parenthesis, but I get a syntax error.

proc format;

value V1format

low - (-0.874999999) = 'A'

-0.875 - (-0.624999999) = 'B'

-0.625 - (-0.374999999) = 'C'

-0.375 - (-0.124999999) = 'D'

-0.124999999 - 0 = 'E'

0-0.1249999999 = 'F'

0.125 - 0.3749999999 = 'G'

0.375 - 0.6249999999 = 'H'

0.625 - 0.8749999999 = 'I'

0.875 - high = 'J';

run;

Any help would be highly appreciated.

Accepted Solutions
Solution
‎10-17-2014 09:06 AM
Super Contributor
Posts: 490

## Re: Negative values in proc format

First:

Your problem is in your logic.

As you know -1 > - 2

so is -.124999999999999 > -.125

that is mean that  when you say

low - (-0.1) = 'A'

-0.2 - (0) = 'B'

you will get overlap, so you can not say

low - -124999999999999 = 'A'

-0.125 - (-0.624999999) = 'B'

Second:

you do not need () in format

Finally:

try this, it should work

proc format;

value V1format

low - -0.875 = 'A'

-0.874999999 - -0.625 = 'B'

-0.624999999 - -0.375 = 'C'

-0.374999999 - -0.125 = 'D'

-0.124999999 - 0 = 'E'

0-0.1249999999 = 'F'

0.125 - 0.3749999999 = 'G'

0.375 - 0.6249999999 = 'H'

0.625 - 0.8749999999 = 'I'

0.875 - high = 'J';

run;

All Replies
Solution
‎10-17-2014 09:06 AM
Super Contributor
Posts: 490

## Re: Negative values in proc format

First:

Your problem is in your logic.

As you know -1 > - 2

so is -.124999999999999 > -.125

that is mean that  when you say

low - (-0.1) = 'A'

-0.2 - (0) = 'B'

you will get overlap, so you can not say

low - -124999999999999 = 'A'

-0.125 - (-0.624999999) = 'B'

Second:

you do not need () in format

Finally:

try this, it should work

proc format;

value V1format

low - -0.875 = 'A'

-0.874999999 - -0.625 = 'B'

-0.624999999 - -0.375 = 'C'

-0.374999999 - -0.125 = 'D'

-0.124999999 - 0 = 'E'

0-0.1249999999 = 'F'

0.125 - 0.3749999999 = 'G'

0.375 - 0.6249999999 = 'H'

0.625 - 0.8749999999 = 'I'

0.875 - high = 'J';

run;

Regular Contributor
Posts: 180

## Re: Negative values in proc format

Try this using ranges excluding one of the values of the range:

proc format;

value V1format

low-<-0.875 = 'A'

-0.875-<-0.625 = 'B'

-0.625-<-0.375 = 'C'

-0.375-<-0.125 = 'D'

-0.125-0 = 'E'

0<-0.125 = 'F'

0.125<-0.375 = 'G'

0.375<-0.625 = 'H'

0.625<-0.875 = 'I'

0.875<-high = 'J';

run;

You can test your format with this small program:

data test;

do number=-880 to 880 by 2;

x=number/1000;

y=put(x,V1format.);

output;

end;

run;

Regards

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 2 replies
• 890 views
• 0 likes
• 3 in conversation