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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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