BookmarkSubscribeRSS Feed
abdullala
Calcite | Level 5
can somebody help me understand how this informat works:

data a;
input d1 $;
cards;
700.1
723.45
166.3
902
991
217.01
98
511
105.45
;
run;

data b;
set a;
format d2 8.2;
d2=input(d1, 8.2);
run;
proc print;
run;

I though I would have values in d2 as numeric form of d1 with 2 digit places. but what I got was this:

Obs d1 d2

1 700.1 700.10
2 723.45 723.45
3 166.3 166.30
4 902 9.02
5 991 9.91
6 217.01 217.01
7 98 0.98
8 511 5.11
9 105.45 105.45

if values in d1 represents an integer (no digit) d2 will add 2 digit places. so 98 becomes 0.98 and 511 becomes 5.11.

I can work around this situation by adding a dot to d1, but can somebody help me understand what happened?
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The SAS numeric variable you assigned is associated with a FORMAT, as you coded, so the PROC PRINT is using that format which is different than what SAS has stored internally. Either remove the SAS FORMAT statement or use another (more revealing) output format such as BEST. in your code.

The SAS DOC has topic discussion about SAS numeric variable precision and storage.

Scott Barry
SBBWorks, Inc.
abdullala
Calcite | Level 5
nah -- didn't work. it only works if I change the informat from '8.2' to 'best.'. I want to know why informat 8.2 does not work. this is not about precision, this is about how informat works. thanks!
Flip
Fluorite | Level 6
The problem seems to be with your input(d1, 8.2) statement. You are telling SAS to read 2 decimal places. Use a best. here and SAS will respect your decimal placement.

so d2 = input(d1, best.);

w.d
Syntax Description

w
specifies the width of the input field.

Range: 1-32

d
optionally specifies the power of 10 by which to divide the value. If the data contain decimal points, the d value is ignored.

Range: 0-31
abdullala
Calcite | Level 5
thank you very much Flip! that's what I have been missing.
Peter_C
Rhodochrosite | Level 12
when your text contains the decimal point never tell a numeric informat how many decimals are present. That feature is needed only where the text has no decimal point.
Use informat 8. or percent8.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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