BookmarkSubscribeRSS Feed
philjones820
Fluorite | Level 6

I'm trying to format these values with 3 decimal places but I keep getting the leading zeroes in front of the decimal place

 

I'm using the following code

 

format AVG 9.3;
format SLG 6.3;
format OBP 9.2;
format ISO 6.3;

format AVG 9.3;
format SLG 6.3;
format OBP 9.3;
format ISO 6.3;

 

format AVG 9.3;
format SLG 6.3;
format AVG 9.3;
format SLG 6.3;
format AVG 9.3;
format SLG 6.3;
format OBP 9.2

 I have attached the Excel output from SAS, please take a look at the AVG, SLG,  OBP and ISO columns O, P,Q and R on the attached spreadsheet and advise

7 REPLIES 7
ScottBass
Rhodochrosite | Level 12

@philjones820 wrote:

I'm trying to format these values with 3 decimal places 

OK

 

but I keep getting the leading zeroes in front of the decimal place

Why do you think the leading zero to the left of the decimal point has anything to do with the 3 decimal places to the right of the decimal point?

 

Can you be ***sure*** your data you want to display without a leading zero is < 1?

 

What would you expect/desire to display in the below example?

 

data test;
   a=0.123456789;
   b=a;
   c=a;
   output;

   a=123.123456789;
   b=a;
   c=a;
   output;

   a=123456.123456789;
   b=a;
   c=a;
   output;

   format a best. b 9.3 c 4.3;
run;

Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Cynthia_sas
SAS Super FREQ
Also, be sure to look at your output in SAS and not just in Excel. Excel is notorious for NOT respecting SAS formats. So depending on how you are sending your output to Excel -- data/PROC EXPORT or report/ODS -- Excel may or may not use the SAS format you want.
Cynthia
philjones820
Fluorite | Level 6

The Excel is output is fine now

have a number 0.573 that I need to format with 3 decimal places in SAS and I though format 9.3 would do that, I don't know if it is supposed to give me 3 decimal places after the 0 like it is now or if I need to remove the 0?

ScottBass
Rhodochrosite | Level 12

See http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199377.htm

 

The 9.3 format will display the number right aligned in a 9 character width field with 3 decimal places to the right of the decimal point.  It will display the integer portion to the left of the decimal point.  If your data is < 1 there will be a zero for the integer portion.

 

IMO suppressing the leading zero in this scenario would be confusing.  I've never had need to do so.


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
ballardw
Super User

@philjones820 wrote:

The Excel is output is fine now

have a number 0.573 that I need to format with 3 decimal places in SAS and I though format 9.3 would do that, I don't know if it is supposed to give me 3 decimal places after the 0 like it is now or if I need to remove the 0?


It may help to show us what you expect the final result to actually look like. You will likely run into an EXCEL display issue. You need to create a custom display in Excel to no show the leading zero if you want to see .573 instead of 0.573.

Highlight the cell(s) in Excel, right click an select "Format Cells", go down and highlight the Custom entry. On the right where it says Type enter .000 and hit enter.

 

You don't mention or show how you are sending data to Excel from SAS. If using report procedure like Proc Print or Report you may be able to use the tagattr style option for the appropriate cell(s).

But if you do have values like 1223.456 that appear in the same  column that is likely going to be a challenge to suppress the 0 for other cells in the column.

ScottBass
Rhodochrosite | Level 12

Sigh...I thought the Excel output was just a convenience to show the data.  If he's trying to format the data *in* Excel then that's a whole different kettle of fish.

 

<frustration>

I sure wish folks would invest as much time in asking a question as they expect us in answering them.

</frustration>


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
philjones820
Fluorite | Level 6
Sorry to confuse you, that was not my intention. The assignment asked for a 3 decimal place format in SAS. I was just using Excel for comparison not formatting. Thanks for your help, will try to invest more time in putting the questions together in the future



SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 7 replies
  • 14006 views
  • 0 likes
  • 4 in conversation