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
- /
- Base SAS Programming
- /
- understanding informat

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

11-11-2009 12:19 PM

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?

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?

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

11-11-2009 12:47 PM

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.

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

Scott Barry

SBBWorks, Inc.

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

11-11-2009 12:55 PM

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!

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

11-11-2009 12:56 PM

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

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

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

11-11-2009 01:08 PM

thank you very much Flip! that's what I have been missing.

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

11-11-2009 01:11 PM

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.

Use informat 8. or percent8.