BookmarkSubscribeRSS Feed
mkop
Calcite | Level 5

I have a variable with data

X= +0.0125

X= +7.90

X= - 0.0076

X= - 0.5

Can anyone help me get all these numbers with same decimal place while keeping the + and - sign in the begining of each number.

Thank you- sign in the begining

3 REPLIES 3
stat_sas
Ammonite | Level 13

Try this.

data have;

input x $;

datalines;

+0.0125

+7.90

-0.0076

-0.5

;

ballardw
Super User

How many decimal points do you want displayed? Do want trailing 0 to pad to that length?

Assuming you want 4 decimals then a custom format such as this should work. Make sure the data is read as numeric not character.

proc format library=work;
picture MyDec
low -<0 = '0009.9999'(prefix='-')
0 - high=  '0009.9999'(prefix='+');
run;

data have;
input x ;
datalines;
+0.0125
+7.90
-0.0076
-0.5
;
run;

proc print data=have;
format x MyDec.;
var x;
run;

Patrick
Opal | Level 21

You've taken exactly the approach I was playing with as well when I run into some "picture" behaviour I didn't understand. https://communities.sas.com/thread/58118

Suggest you add "round" to your format like data _null_ suggested in the link posted.

...and: I believe '0' should just be '0' and not +0

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →

Health and Life Sciences Learning

 

Need courses to help you with SAS Life Sciences Analytics Framework, SAS Health Cohort Builder, or other topics? Check out the Health and Life Sciences learning path for all of the offerings.

LEARN MORE

Discussion stats
  • 3 replies
  • 4291 views
  • 0 likes
  • 4 in conversation