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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

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