<?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: Relative Rounding in the Data step. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978644#M378664</link>
    <description>&lt;P&gt;I have a silly (?) question: why do you only have one comma in&amp;nbsp;345,123456&amp;nbsp; and several other of your example values? Normally when I see a single comma in a value with that many digits I have to assume comma is from one of the languages that uses a comma for separating the decimal and a . for the thousands separator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach would be use a custom format with differing digit selectors based on range of values but that would normally have multiple commas in those values.&lt;/P&gt;</description>
    <pubDate>Tue, 11 Nov 2025 06:21:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2025-11-11T06:21:23Z</dc:date>
    <item>
      <title>Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978560#M378627</link>
      <description>&lt;P&gt;I have a question: What tools are there in the Data-step make a Relative Rounding of a numeric number?&lt;/P&gt;
&lt;P&gt;I know about the ROUND, ROUNDE and ROUNDZ functions. &lt;BR /&gt;But they make an Absolute rounding.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Population is some countries:&lt;/P&gt;
&lt;P&gt;345,123456&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 34,123456&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;3,123456&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 123456&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 23456&lt;/P&gt;
&lt;P&gt;But the user rather wants relative rounding to e.g.3 digits, like&lt;/P&gt;
&lt;P&gt;345,000000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;34,100000&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3,120000&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; 123000&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 23400&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Yes I have some ideas about to achieve this - if it is not already solved.&lt;BR /&gt;&amp;nbsp;Please omit any misprint - Some Covid-19 look alike here)&lt;/P&gt;
&lt;P&gt;/Br Anders Sköllermo - Skollermo in English&lt;/P&gt;</description>
      <pubDate>Sat, 08 Nov 2025 14:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978560#M378627</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2025-11-08T14:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978563#M378629</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input n;
cards;
345123456  
34123456
3123456
123456
23456
;
run;

data want;
set test;
n_round=round(n/1000)*1000;
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Nov 2025 14:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978563#M378629</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-11-08T14:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978564#M378630</link>
      <description>Hi! Yes this solves the simple example problem.&lt;BR /&gt; BUT next level - decimal numbers.&lt;BR /&gt;Third level: A mix of Relative and Absolute rounding.</description>
      <pubDate>Sat, 08 Nov 2025 14:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978564#M378630</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2025-11-08T14:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978568#M378632</link>
      <description>&lt;P&gt;If you want to keep N digits for any magnitude number then first use LOG10() to figure out the magnitude of the number.&amp;nbsp; Then you can adjust the factor your multiple/divide by in that formula.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you set the macro variable NDIGITS to represent the number of digits you want to keep the formula could be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;factor = 10 ** (floor(log10(X))-(&amp;amp;ndigits-1));
X_round=round(X/factor)*factor;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let ndigits=3;
data test;
  input n;
  log=floor(log10(n));
  factor = 10 ** (log-(&amp;amp;ndigits-1));
  n_round=round(n/factor)*factor;
cards;
345123456
34512345
3451234
345123
34512
3451
345.1
34.51
3.451
.3451
.03451
.003451
;

proc print;
  format n best20.3 n_round comma20.6 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1762615571722.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/111219i821CDB8B0CDFD81B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1762615571722.png" alt="Tom_0-1762615571722.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note you can skip the multiplication and division and just let the ROUND() function do it for you by using the optional second argument.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  n_round=round(n,10 ** (floor(log10(n))-(&amp;amp;ndigits-1)));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Nov 2025 17:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978568#M378632</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-11-08T17:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978604#M378645</link>
      <description>&lt;P&gt;Hi! VERY nice solution.&lt;BR /&gt;I had an idea of using PUT and SUBSTR.&amp;nbsp;&lt;BR /&gt;I will have a look at this nice solution and my own (unfinished) work.&lt;BR /&gt;Nice discussions!&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;/Br Anders Sköllermo - Skollermo in English&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Nov 2025 14:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978604#M378645</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2025-11-10T14:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978644#M378664</link>
      <description>&lt;P&gt;I have a silly (?) question: why do you only have one comma in&amp;nbsp;345,123456&amp;nbsp; and several other of your example values? Normally when I see a single comma in a value with that many digits I have to assume comma is from one of the languages that uses a comma for separating the decimal and a . for the thousands separator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach would be use a custom format with differing digit selectors based on range of values but that would normally have multiple commas in those values.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Nov 2025 06:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978644#M378664</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-11-11T06:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Relative Rounding in the Data step.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978676#M378669</link>
      <description>Hi! Good question about the comma. You are quite right. /Br AndersS</description>
      <pubDate>Tue, 11 Nov 2025 14:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Relative-Rounding-in-the-Data-step/m-p/978676#M378669</guid>
      <dc:creator>AndersS</dc:creator>
      <dc:date>2025-11-11T14:01:11Z</dc:date>
    </item>
  </channel>
</rss>

