turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Decimal specification

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-28-2015 03:00 AM

I'm trying to import data from .txt file. 2 columns are of length 9.19 and 5.8 in the source file;

But in SAS when I write a FORMAT with 9.19 and 5.8, it errors out stating

"decimal specification must be less than the width specification". Can you please help. Thank you!

data temp;

infile "/directory/sample.txt" delimiter = '|' MISSOVER DSD lrecl=32767 firstobs=2 ;

INPUT

VAR1 :10.

VAR2 :6.

;

FORMAT

VAR1 9.19

VAR2 5.8

;

run ;

Thank you!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-28-2015 10:23 AM

Can you give us an example of the values you're trying to read and how you want them to be formatted please. With 9.19 you're asking SAS to give you 19 decimal places with a total width of only 9, so it doesn't work.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-28-2015 11:36 AM

Format specification is w.d

w

specifies the width of the output field.

Range: | 1-32 |

Tip: | Allow enough space to write the value, the decimal point, and a minus sign, if necessary. |

specifies the number of digits to the right of the decimal point in the numeric value. This argument is optional.

Range: | 0-31 |

Requirement: | must be less than w |

Tip: | If d is 0 or you omit d, w.d writes the value without a decimal point. |

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

W = 8.2

WWWWW.DD

Also, I don't think you can have 19 decimal places, IEEE floating point number rules.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-28-2015 12:29 PM

What do you think 9.19 means? Is that 9 digits before the decimal point + the decimal point + 19 digits after the decimal point?

If so then the width of that field will be 29 characters with 28 digits of precision. So in your FORMAT statement you should use 29.19 (which can also be written as F29.19).

But you cannot store 28 digits of precision in a floating point number. So either

1) Remove the format for that variable from the INPUT statement.

SAS will then just do the best it can to convert the data it sees into a floating point number. You might lose some digits of precision.

2) Read it as character. You could do that by using :$29. as the format on the INPUT statement. There is no need to attach a format to character variables in your FORMAT statement.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-28-2015 12:34 PM

SAS uses 8 byte floating point for numeric variables, which provides a maximum of 15 significant digits. If you need more, you'll have to capture the data as character, but you won't be able to perform calculations on it.

Tom