Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

[ Edited ]

Hi All,

 

I request you to help me rounding mean value  -0.00015367 to -0.000 , when i round by using below code 

STRIP(PUT(round(MEAN,0.001),8.3)); I am getting 0.000

If I increase decimals to round(MEAN,0.0001) {x=STRIP(PUT(round(MEAN,0.0001),8.3)); }
in order to get -0.000 but this may effect other data ,if possible please do help me with other way of doing..

 

Thanks in Advance..


Accepted Solutions
Solution
‎06-27-2017 03:24 AM
Respected Advisor
Posts: 4,132

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

[ Edited ]

@ettinenivarma

I believe you could make this work via a custom format.

proc format;
  value fin_fmt(default=10)
     -0.0005 <-< 0    = '-0.000'
    other         =[f32.3]
    ;
run;

data test;
  do i= -0.001 to +0.001 by 0.000001;
    value_num=i;
    value_char=put(i,fin_fmt.);
    value_round=round(i,0.001);
    output;
  end;
  format value_num fin_fmt. i best32.;
run;

 

 

Capture.JPG

View solution in original post


All Replies
Trusted Advisor
Posts: 1,137

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

 

Please dont round just convert as below 

 

data have;
x=-0.00015367;
x2=put(x,8.3);
put x2=;
run;
Thanks,
Jag
Occasional Contributor
Posts: 12

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Thanks for quick response.

Your below code gives required output (It truncates ) for that record when i had 0.000XXX but i required do rounding when i had value other then zero value 

 

Trusted Advisor
Posts: 1,789

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000


ettinenivarma wrote:

Hi All,

 

I request you to help me rounding mean value  -0.00015367 to -0.000 , when i round by using below code 

STRIP(PUT(round(MEAN,0.001),8.3)); I am getting 0.000

If I increase decimals to round(MEAN,0.0001) {x=STRIP(PUT(round(MEAN,0.0001),8.3)); }
in order to get -0.000 but this may effect other data ,if possible please do help me with other way of doing..

 

Thanks in Advance..


So maybe you mean something different by the word "rounding" than the ROUND function in SAS means, and something different than the normal mathematical meaning of the word "rounding".

 

You are doing this "rounding" and creating characters, not numbers, is that really what you want? If so, then I think your code works, and I don't understand the point of your question.

 

I also don't understand "but this may effect [sic] other data". Could you explain?

 

 

Occasional Contributor
Posts: 12

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Yes your correct i mean to say round funcation it self ,Yes my end varaible should be char.

Other data means ,in my varaible i had many observation like mean ,sd  values etc..

 for example : when i round   -0.00015367 by using above code i get 0.000 but my requirment is -0.000.

 

Thanks for your response

PROC Star
Posts: 7,433

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Would the following suffice?:

data have;
  input mean;
  rmean=round(MEAN,.001);
  if mean lt 0 then rmean=rmean-.00001;
  x=PUT(rmean,8.3);
  cards;
-0.00015367
0
0.00015367
;

Art, CEO, AnalystFinder.com

Occasional Learner
Posts: 1

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

[ Edited ]

 But  could not do hardcoding ".00001" because that  variable may contain other  values in real time data

 

Thanks your post sir 

Occasional Contributor
Posts: 12

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Yes, I can not do hardcording of values...

PROC Star
Posts: 7,433

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Couldn't you do hard coding for that one case? e.g.:

data have;
  input mean;
  rmean=round(MEAN,.001);
  if mean lt 0 and rmean eq 0 then rmean=rmean-.00001;
  x=PUT(rmean,8.3);
  cards;
-0.00015367
0
0.00015367
;

Art, CEO, AnalystFinder.com

Super User
Posts: 19,155

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

[ Edited ]

@ettinenivarma You use the same function, we don't have your code or data or computer in front of us so you're not going to get something that's exact for your code. The 'hardcoding' is for testing and demonstration purposes with the intention that you take the formula and use it on your data with your own variables. 

 

Please disregard above, this is not correct for your situation. Note that 0 is well 0, there's no sign attached to it, which is why you're seeing those results.

 

The solution proposed by @Jagadishkatam seems to produce what you want though, otherwise you're probably likely to need to create your own custom function/format.

 

want = put(myVariable, 8.3);

 

 

 

 

 

Occasional Contributor
Posts: 12

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Hi Reeza,

Thanks for response.

I to convenced same to my boss saying 0 is 0 there will not be any sign to it, he said as it is financial data he wants as suggested above. I already tryied applying round function and put as well but I want to  trying different way of doing to get minus.

 

Any way thanks all  for suggestion and inputs 

Solution
‎06-27-2017 03:24 AM
Respected Advisor
Posts: 4,132

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

[ Edited ]

@ettinenivarma

I believe you could make this work via a custom format.

proc format;
  value fin_fmt(default=10)
     -0.0005 <-< 0    = '-0.000'
    other         =[f32.3]
    ;
run;

data test;
  do i= -0.001 to +0.001 by 0.000001;
    value_num=i;
    value_char=put(i,fin_fmt.);
    value_round=round(i,0.001);
    output;
  end;
  format value_num fin_fmt. i best32.;
run;

 

 

Capture.JPG

Occasional Contributor
Posts: 12

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Thanks sir
Occasional Contributor
Posts: 12

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

Thanks Patrick for your input
Respected Advisor
Posts: 4,132

Re: Please help me on rounding the value to 3 decimals places -0.00015367 to -0.000

@ettinenivarma

I believe a custom format is the easiest solution for you.

Financial reports often use Proc Report and should your boss be very demanding then you can also add conditional formatting to make him/her happy as documented here: http://support.sas.com/kb/23/353.html

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 18 replies
  • 275 views
  • 3 likes
  • 9 in conversation