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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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