BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ettinenivarma
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

18 REPLIES 18
Jagadishkatam
Amethyst | Level 16

 

Please dont round just convert as below 

 

data have;
x=-0.00015367;
x2=put(x,8.3);
put x2=;
run;
Thanks,
Jag
ettinenivarma
Fluorite | Level 6

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 

 

PaigeMiller
Diamond | Level 26

@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?

 

 

--
Paige Miller
ettinenivarma
Fluorite | Level 6

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

art297
Opal | Level 21

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

varmae
Calcite | Level 5

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

 

Thanks your post sir 

ettinenivarma
Fluorite | Level 6

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

art297
Opal | Level 21

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

Reeza
Super User

@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);

 

 

 

 

 

ettinenivarma
Fluorite | Level 6

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 

Patrick
Opal | Level 21

@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

Patrick
Opal | Level 21

@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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 18 replies
  • 3999 views
  • 3 likes
  • 9 in conversation