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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 7717 views
  • 0 likes
  • 3 in conversation