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
- /
- Round giving unexpected result

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-26-2016 04:08 PM

HI,

I have a value x=0.032949.

if x >= **0.0001** then y=put(round(x,**0.0001**),**7.4**);

I am getting x=0.017.

Where as I should be getting 0.0329.

Why is this happening?

How do I fix this?

Thanks,

Archana

Accepted Solutions

Solution

05-19-2016
11:09 AM

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

Posted in reply to ArchanaSudhir

04-26-2016 04:25 PM

Post your full code and the log.

I suspect something is going on with your y variable as I can't reproduce your error with this program:

```
data junk;
x=0.032949;
if x >= 0.0001 then y=put(round(x,0.0001),7.4);
run;
```

I get the expected value.

And your reason for not using y=put(x,7.4); is exactly what?

All Replies

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

Posted in reply to ArchanaSudhir

04-26-2016 04:20 PM

SAS version? OS?

I couldn't repeat your issue.

23 data _null_ ; 24 x=0.032949; 25 y=put(round(x,0.0001),7.4); 26 put y=; 27 run; y=0.0329 NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds

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

Posted in reply to ArchanaSudhir

04-26-2016 04:21 PM

Following syntax is giving right numbers. Look for Y variable instead of X for rounded numbers

data _null_;

x=0.032949;

if x >= 0.0001 then y=put(round(x,0.0001),7.4);

put _all_;

run;

Solution

05-19-2016
11:09 AM

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

Posted in reply to ArchanaSudhir

04-26-2016 04:25 PM

Post your full code and the log.

I suspect something is going on with your y variable as I can't reproduce your error with this program:

```
data junk;
x=0.032949;
if x >= 0.0001 then y=put(round(x,0.0001),7.4);
run;
```

I get the expected value.

And your reason for not using y=put(x,7.4); is exactly what?