<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Round to 2 digits after decimal in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844815#M333988</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Apply format will not help me because I need to change the real number and not just change format.&lt;BR /&gt;The reason is that I need to merge the data with another data set (and in the other data set the numbers are with 4 digits after point)&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, be sure that what you see from one variable where it always has two digits after the decimal is not caused by a format, check the unformatted values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing the merge/join in SQL, you don't need to create a new variable. You just need the ROUND function in the ON part of an SQL call, for example if a.variablename is the data set that has values with 2 digits after the decimal and b.variablename2 has lots of decimal places, use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.variablename = round(b.variablename2, 0.01)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing this merge in a DATA step, then you probably do need to create a new variable to contain the rounded value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This of course brings up the issue, discussed many times here in the SAS Communities, of machine precision, where the values still may not match (depending on how they were created) in the 15th decimal place, for example, and so you might have to round both variables (even though it appears that the one is already rounded to 2 decimal places).&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 13:39:37 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-11-17T13:39:37Z</dc:date>
    <item>
      <title>Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844794#M333980</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to round these numbers to 2 numbers after digits:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5.750000&amp;nbsp; to 5.75&lt;/P&gt;
&lt;P&gt;1.683700 to 1.68&lt;/P&gt;
&lt;P&gt;4.0663&amp;nbsp; to 4.07&lt;/P&gt;
&lt;P&gt;6.2703&amp;nbsp; to 6.27&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also dont think that this activity is called round because actually I need to take 2 numbers after point&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 11:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844794#M333980</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-11-17T11:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844796#M333981</link>
      <description>&lt;P&gt;Apply the 8.2 format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input num;
format num 8.2;
datalines;
5.750000 
1.683700 
4.0663   
6.2703   
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 11:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844796#M333981</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T11:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844797#M333982</link>
      <description>Apply format will not help me because I need to change the real number and not just change format.&lt;BR /&gt;The reason is that I need to merge the data with another data set (and in the other data set the numbers are with 4 digits after point)</description>
      <pubDate>Thu, 17 Nov 2022 11:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844797#M333982</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-11-17T11:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844798#M333983</link>
      <description>&lt;P&gt;I want to have full match because the 2 digits after point are matched and the numbers before points are matched.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have1;
input num;
format num 8.2;
datalines;
5.750000 
1.683700 
4.0663   
6.2703   
;
Run;


data have2;
input num;
format num 8.2;
datalines;
5.75
1.68
4.06  
6.27 
;
Run;

proc sql;
create table want as
select a.num
from have1 as a
inner join have2 as b
on a.num=b.num
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 11:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844798#M333983</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-11-17T11:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844799#M333984</link>
      <description>&lt;P&gt;I see. Try this approach to numeric truncation without rounding then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input num;
trunc = int(num*10**2)/10**2;
datalines;
5.750000 
1.683700 
4.0663   
6.2703   
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 11:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844799#M333984</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T11:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844812#M333987</link>
      <description>&lt;P&gt;From the numbers shown you do what i learned some decades ago as "rounding".&lt;/P&gt;
&lt;P&gt;So round(variable, 0.01) should give you what you want.&lt;/P&gt;
&lt;P&gt;Remember to apply the function whenever values with decimals are checked for equality, because on every computer 0.1 is not the always the same as 0.1 - this has been explained so many times, i abstain from repeating it here.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 12:26:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844812#M333987</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-11-17T12:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: Round to 2 digits after decimal</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844815#M333988</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Apply format will not help me because I need to change the real number and not just change format.&lt;BR /&gt;The reason is that I need to merge the data with another data set (and in the other data set the numbers are with 4 digits after point)&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;First, be sure that what you see from one variable where it always has two digits after the decimal is not caused by a format, check the unformatted values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing the merge/join in SQL, you don't need to create a new variable. You just need the ROUND function in the ON part of an SQL call, for example if a.variablename is the data set that has values with 2 digits after the decimal and b.variablename2 has lots of decimal places, use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on a.variablename = round(b.variablename2, 0.01)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing this merge in a DATA step, then you probably do need to create a new variable to contain the rounded value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This of course brings up the issue, discussed many times here in the SAS Communities, of machine precision, where the values still may not match (depending on how they were created) in the 15th decimal place, for example, and so you might have to round both variables (even though it appears that the one is already rounded to 2 decimal places).&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 13:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Round-to-2-digits-after-decimal/m-p/844815#M333988</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-11-17T13:39:37Z</dc:date>
    </item>
  </channel>
</rss>

