BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mark_ph
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11

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;

View solution in original post

2 REPLIES 2
mohamed_zaki
Barite | Level 11

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;

CTorres
Quartz | Level 8

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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