BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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;

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

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;
ed_sas_member
Meteorite | Level 14
proc format;
picture parenthesis (round) low-high="0009.00)" (prefix="(");
run;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 969 views
  • 2 likes
  • 3 in conversation