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
- /
- how to get percentage as 99.9

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

03-10-2018 10:07 AM

When I'm using format as 5.1 or 6.1 on z variable , I'm getting 100 percentage in z variable. I need it 99.9 as required output .please someone suggest on it...

data _null_;

x = 2202;

y= 2203;

z=x/y*100;

z1 = put(z,5.1);

put x y z z1= ;

run;

Accepted Solutions

Solution

03-11-2018
11:30 AM

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

Posted in reply to rajeshalwayswel

03-10-2018 10:31 AM

Hi:

A picture format will not round the number. Here's some code to test, a slightly different version of your code.

```
proc format;
picture pctnr low-high='099.9';
run;
data nums;
length z2 $5;
x = 2202;
y= 2203;
z=x/y*100;
z1=z;
z2 = put(z,pctnr.);
put x= y= z= z1= z2=;
run;
proc print data=nums label;
var x y z z1 z2;
label z='z uses sas format'
z1='z1 uses picture custom format'
z2='z2 is char var using picture format';
format z 5.1 z1 pctnr.;
run;
```

Cynthia

All Replies

Solution

03-11-2018
11:30 AM

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

Posted in reply to rajeshalwayswel

03-10-2018 10:31 AM

Hi:

A picture format will not round the number. Here's some code to test, a slightly different version of your code.

```
proc format;
picture pctnr low-high='099.9';
run;
data nums;
length z2 $5;
x = 2202;
y= 2203;
z=x/y*100;
z1=z;
z2 = put(z,pctnr.);
put x= y= z= z1= z2=;
run;
proc print data=nums label;
var x y z z1 z2;
label z='z uses sas format'
z1='z1 uses picture custom format'
z2='z2 is char var using picture format';
format z 5.1 z1 pctnr.;
run;
```

Cynthia

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

Posted in reply to rajeshalwayswel

03-10-2018 11:12 AM

Be advised that 99.9 will be mathematically wrong, as 99.954607354 must be rounded *up* (per definition) if only 1 fractional digit can be displayed.

The more correct method would be to use a 5.2 format in the put() function.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code

Maxims of Maximally Efficient SAS Programmers

How to convert datasets to data steps

How to post code