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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.