The results from this program show which formats round values. If the
variables C1 and C2 have the same value, then rounding is taking
place. For formats that produce different values for C1 and C2, the
values should be rounded with the ROUND function to two decimal places (for the formats used in this example) before using the format.
The results vary across operating systems due to numeric
representation differences.
%LET V1= -.025;
%LET V2= -.030;
%LET FMTLIST= 6.2 COMMA6.2 COMMAX6.2 DOLLAR6.2 DOLLARX6.2 EURO6.2
EUROX6.2 IEEE6.2 IEEER6.2 NEGPAREN6.2 NUMX6.2 OCTAL6.2 PD6.2 PK6.2
RB6.2 S370FF6.2 S370FPD6.2 S370FPDU6.2 S370FRB6.2 S370FZD6.2
S370FZDL6.2 S370FZDS6.2 S370FZDT6.2 S370FZDU6.2 TIME6.2 VAXRB6.2
YEN6.2 Z6.2 ZD6.2;
%MACRO LOOP;
DATA _NULL_;
IF ROUND(&V1,.01) = ROUND(&V2,.01) THEN
PUT "ROUNDING &V1 AND &V2 ARE THE SAME ";
ELSE PUT "ROUNDING &V1 AND &V2 ARE DIFFERENT ";
%LET I=1;
%LET FMT=%SCAN(&FMTLIST,&I,%STR( ));
%DO %WHILE (&FMT NE );
C1=PUT(&V1,&FMT); C2=PUT(&V2,&FMT);
IF PUT(&V1,&FMT) = PUT(&V2,&FMT) THEN
PUT "&FMT" @13 "&V1 AND &V2 SAME "
@38 (C1 C2) (= $HEX.) /
@38 (C1 C2) (=);
ELSE PUT "&FMT" @13 "&V1 AND &V2 DIFF "
@38 (C1 C2) (= $HEX.) /
@38 (C1 C2) (=);
PUT;
%LET I=%EVAL(&I+1);
%LET FMT=%SCAN(&FMTLIST,&I,%STR( ));
%END;
RUN;
%MEND;
%LOOP