Help using Base SAS procedures

A numeric format with blanks between 3 digits

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

A numeric format with blanks between 3 digits

Hello everyone,

I think most of you aware of a format COMMAw.d which prints number, say, 123456789.12 as

123,456,789.12

I'm trying to find quite similiar format which will print the same number in a manner

123 456 789.12

or even

123 456 789,12

Since I haven't find built in one I tried to create picture by myself using proc format

proc format;

   picture test low-high='00 000 000 000 000.00';

run;o

Okay, it seems to work for the number I chose, but what about 20 digit length numbers?

According to SAS Help, I can't use picture string with more than 16 digits.

What to do in this situation? (P.s. Comma. format works fine with up to 40 digits).


Accepted Solutions
Solution
‎11-19-2012 06:25 AM
Super User
Posts: 5,431

Re: A numeric format with blanks between 3 digits

Posted in reply to ghastly_kitten

For your second alternative, it could be accomplished using the nlnum. format, just be sure to have the appropriate locale set.

https://support.sas.com/documentation/cdl/en/nlsref/63072/HTML/default/viewer.htm#p1sunvzyp4dw9nn1pa...

Data never sleeps

View solution in original post


All Replies
Solution
‎11-19-2012 06:25 AM
Super User
Posts: 5,431

Re: A numeric format with blanks between 3 digits

Posted in reply to ghastly_kitten

For your second alternative, it could be accomplished using the nlnum. format, just be sure to have the appropriate locale set.

https://support.sas.com/documentation/cdl/en/nlsref/63072/HTML/default/viewer.htm#p1sunvzyp4dw9nn1pa...

Data never sleeps
Contributor
Posts: 41

Re: A numeric format with blanks between 3 digits

Any hint about specific locale?

I have Russia_Russian, but it's still uses comma as a 3digit separator, and I need a blank space.

Super User
Posts: 5,431

Re: A numeric format with blanks between 3 digits

Posted in reply to ghastly_kitten

Sweden has blanks... (sv_SE)

Data never sleeps
Contributor
Posts: 41

Re: A numeric format with blanks between 3 digits

Thanks!

I wonder why Russian has commas... It's a question for SAS support: it must be blanks for digit separating and a comma for decimal.

upd. I used NLNUM. instead of NLNUMI for my locale. And it worked.

LinusH, thanks anyway!

Super Contributor
Posts: 644

Re: A numeric format with blanks between 3 digits

Posted in reply to ghastly_kitten

A couple of things to note

  1. Windows and Unix SAS (unless I blinked and missed the upgrade) use the IEEE system of representing floating point numbers in 8 bytes.  This restricts the accuracy of representing any integer to just short of 16 digits.  MS Excel has the same limitation - try entering a 16 digit number and it will truncate the last digit to zero.  SAS is better behaved but anything after the first 15 digits in your format cannot be relied on. 
  2. Picture formats with decimals do not round to nearest decimal.  Instead they always round down.  This can catch you out because what looks like 12345.6700 when you view your table using best12.4 may be a tiny amount short of that and picture would represent it as 12345.6699.

Oracle uses a 12 byte internal representation for numeric values so you commonly see 23 digits specified.  I believe you can have extended precision in FORTRAN, if that helps.

Richard in Oz

Contributor
Posts: 41

Re: A numeric format with blanks between 3 digits

Posted in reply to RichardinOz

Richard, thanks!

I've totally forgot about the 8 byte limitation for floats... Despite of seeing this fact in every computer science course I've ever taken.

Actually, I don't really need such an accuracy, I just need the format that will be universal (like any internal format).

So I can use it with numbers of different power (assuming the power of a column is the same through the dataset).

I.e. when I'm using a picture for the format, the number of digit selectors must be 16, but the place of decimal separator "." is predefined.

And that's a problem, because for different powers of the number (that I want to print) I'll need to redefine the format in order to have 16 digits and a "." in appropriate place.

Example:

1234567890.123456 and  123456789012345.6

I can use CommaW.D to set the correct formatting (without using the redifinition of format).

I can't use any picture created by proc format, because in both numbers, independently of (w.d), some part will be truncated.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 2262 views
  • 7 likes
  • 3 in conversation