smilepj
smilepj

Reputation: 42

Why does comma9.2 not work?

Can anyone tell me why comma9.2 is not working in my sas codes?

data have;
input x $16.;
y = input(x, comma9.2);
z = input(x, comma9.);
put x= y= z= ;
cards;
1,740.32
5200
520
52
7,425
9,000.00
36,000.00
;
run;

Upvotes: 0

Views: 798

Answers (2)

Joe
Joe

Reputation: 63424

To expand on Reeza's answer:

Informat decimal places do not quite work the way Format decimal places do. In almost all cases, you will not want to or need to specify the d in the informat. Comma9. is almost always correct, no matter how many decimal places you expect - even if you expect always two.

The only use informat decimal places serve is when you have a number like 12345600, which has no decimal in it, but it ought to (the last two zeros are after the decimal).

data _null_;
  input numval 8.2;
  put numval=;
  datalines;
12345600
12345605
99999989
1857.145
;;;;
run;

This was something that was common once upon a time in the age of punch cards, particularly for accounting; since everything was in dollars and cents, you could save a column by leaving out the decimal, and just read everything in with two decimals. It is no longer common in most fields (at least in my experience), but SAS is always backwards compatible.

SAS will ignore the .d specification if it encounters a decimal point in the data (and will then use the location of that decimal to read in the value correctly), but if there are no decimal points in the data it may read it in incorrectly if you specify the .d. Notice in my example the final row has a decimal point followed by three decimal places, and is read in correctly.

You can read SAS Documentation for more information.

Upvotes: 2

Reeza
Reeza

Reputation: 21274

Comma9.2 assumes that values will always have 2 decimal places.

Upvotes: 0

Related Questions