BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ghastly_kitten
Fluorite | Level 6

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).

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

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

6 REPLIES 6
LinusH
Tourmaline | Level 20

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
ghastly_kitten
Fluorite | Level 6

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.

LinusH
Tourmaline | Level 20

Sweden has blanks... (sv_SE)

Data never sleeps
ghastly_kitten
Fluorite | Level 6

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!

RichardinOz
Quartz | Level 8

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

ghastly_kitten
Fluorite | Level 6

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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 8646 views
  • 7 likes
  • 3 in conversation