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.
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;
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;
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.