I created a custom format to enclose numbers using parentheses, so
data have;
input x @@;
cards;
1.234 5.678 9.012 3.456 7.890
;
run;
I applied the following format.
proc format;
picture parenthesis low-<0="0009.00)" (prefix="(-") 0-high="0009.00)" (prefix="(");
run;
And printed as follows.
data _null_;
set have;
format x parenthesis.;
put _all_;
run;
Here is the log output.
x=(1.23) _ERROR_=0 _N_=1 x=(5.67) _ERROR_=0 _N_=2 x=(9.01) _ERROR_=0 _N_=3 x=(3.45) _ERROR_=0 _N_=4 x=(7.89) _ERROR_=0 _N_=5
(1) Similar to ready-made SAS formats, can I make the new format PARENTHESIS flexible using w and ds? For example. I want to obtain something PARENTHESIS12.4 or PARENTHESIS8.2.
(2) This format does not round each number—the second output displays (5.67) despite the original value 5.678. I tried ROUND right after PREFIX but failed. Where should I adjust? Thanks.
ROUND goes inside brackets just after the picture name:
proc format;
picture parenthesis (round)
low-<0="0009.00)" (prefix="(-")
0-high="0009.00)" (prefix="(");
run;
ROUND goes inside brackets just after the picture name:
proc format;
picture parenthesis (round)
low-<0="0009.00)" (prefix="(-")
0-high="0009.00)" (prefix="(");
run;
proc format;
picture parenthesis (round) low-high="0009.00)" (prefix="(");
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.