<?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: How to round to 3 significant figures for this specific presentation? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837387#M331083</link>
    <description>Hey Mike, thanks for the reply. The final result I'm looking for is how I have it screenshot in the original post. There is some code doing a quick online search on how to get 3 significant figures, but the difficulty I'm having is attaching 1 zero at the end of the values in row 3 and row 4. I'm sure there has to be some kind of conditional logic I have to use to be able to do it, but I was looking for a more efficient way.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 07 Oct 2022 13:26:01 GMT</pubDate>
    <dc:creator>Hello_there</dc:creator>
    <dc:date>2022-10-07T13:26:01Z</dc:date>
    <item>
      <title>How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837334#M331056</link>
      <description>&lt;P&gt;Hi, I'm trying to figure out the coding for how I can format this data set into 3 significant figures with the exact presentation listed below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input x;
datalines;
31.45
0.02355
0.45
34
4723
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_0-1665129257233.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76007iC8A25AEB34B13218/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_0-1665129257233.png" alt="Hello_there_0-1665129257233.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 07:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837334#M331056</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-10-07T07:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837380#M331080</link>
      <description>&lt;P&gt;I am not entirely sure what format you want to add, as the data has changed in various different way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If what you are asking, is to have 3 decimals then a format like this should do the job:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
format x comma10.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will give you this result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mike_j_0-1665148550886.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76011i5429DC575ADE907F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mike_j_0-1665148550886.png" alt="Mike_j_0-1665148550886.png" /&gt;&lt;/span&gt;&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>Fri, 07 Oct 2022 13:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837380#M331080</guid>
      <dc:creator>Mike_j</dc:creator>
      <dc:date>2022-10-07T13:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837387#M331083</link>
      <description>Hey Mike, thanks for the reply. The final result I'm looking for is how I have it screenshot in the original post. There is some code doing a quick online search on how to get 3 significant figures, but the difficulty I'm having is attaching 1 zero at the end of the values in row 3 and row 4. I'm sure there has to be some kind of conditional logic I have to use to be able to do it, but I was looking for a more efficient way.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837387#M331083</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-10-07T13:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837401#M331091</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could create a format based on a user-defined function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x;
datalines;
31.45
0.02355
0.45
34
4723
-9994.999
-9995
-1.235e-15
0
9.876e15
9.999e15
.
.A
;

proc fcmp outlib=work.funcs.test;
function sig3dig(x) $32;
  length f $32;
  if x then do;
    m=floor(log10(abs(x)));
    y=round(x,10**(m-2));
    m=floor(log10(abs(y)));
    f=if m&amp;gt;1 then left(put(y,32.))
             else left(putn(y,cat('32.',2-m)));
  end;
  else f=put(x,1.);
  return(f);
endsub;
run;

options cmplib=work.funcs;

proc format;
value sig3dig (default=32)
other=[sig3dig()];
run;

proc print data=have;
format x sig3dig.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This should work for numbers with absolute values in a range from about 1E-15 through 1E16. (I assume that the "31.6" in your sample output is a typo and should read 31.5.)&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837401#M331091</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-07T13:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837404#M331094</link>
      <description>Thanks, FreelanceReinhard!&lt;BR /&gt;&lt;BR /&gt;This code does the job and I appreciate it. This type of coding is new stuff that I've never seen before, so it gives me an opportunity to learn what it does. &lt;BR /&gt;&lt;BR /&gt;Thanks again!</description>
      <pubDate>Fri, 07 Oct 2022 13:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837404#M331094</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-10-07T13:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837446#M331103</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hey Mike, thanks for the reply. The final result I'm looking for is how I have it screenshot in the original post. There is some code doing a quick online search on how to get 3 significant figures, but the difficulty I'm having is attaching 1 zero at the end of the values in row 3 and row 4. I'm sure there has to be some kind of conditional logic I have to use to be able to do it, but I was looking for a more efficient way.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How do you know the zeros belong at the end of the third and fourth values?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is :&lt;/P&gt;
&lt;P&gt;How do you know that&amp;nbsp;0.45 was measured to the thousandths place and not the hundreds place?&lt;/P&gt;
&lt;P&gt;And how do you know that&amp;nbsp;34 was measured to the tenths place instead of the ones place?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 18:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/837446#M331103</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-07T18:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/953371#M372474</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; , is there a way to make this function dynamic, so that i can have an argument for the number of significant digits i want it to extend to? For example, this function goes out 3 places only. Do you know how i would be able to have it in case i wanted to go out to only 2 places or 4 places?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 13:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/953371#M372474</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2024-12-12T13:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/953374#M372475</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/252358"&gt;@Hello_there&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, we can add the number &lt;EM&gt;n&lt;/EM&gt; of significant digits as the first argument:&lt;/P&gt;
&lt;PRE&gt;proc fcmp outlib=work.funcs.test;
function &lt;STRONG&gt;sigdig&lt;/STRONG&gt;(&lt;STRONG&gt;n&lt;/STRONG&gt;, x) $32;
  length f $32;
  if x then do;
    m=floor(log10(abs(x)));
    y=round(x,10**(m-&lt;STRONG&gt;n+1&lt;/STRONG&gt;));
    m=floor(log10(abs(y)));
    f=if m&amp;gt;&lt;STRONG&gt;n-2&lt;/STRONG&gt; then left(put(y,32.))
             else left(putn(y,cat('32.',&lt;STRONG&gt;n-1&lt;/STRONG&gt;-m)));
  end;
  else f=put(x,1.);
  return(f);
endsub;
run;

options cmplib=work.funcs;&lt;/PRE&gt;
&lt;P&gt;(Changes to the definition of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;sig3dig&lt;/FONT&gt;&amp;nbsp;are highlighted in boldface.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test of the new function using the HAVE dataset from the original solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
x1=sigdig(1,x);
x2=sigdig(2,x);
x3=sigdig(3,x);
x4=sigdig(4,x);
x5=sigdig(5,x);
x9=sigdig(9,x);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that we &lt;EM&gt;cannot&lt;/EM&gt; use the new function in a PROC FORMAT step because it requires two arguments. But we could define separate functions &lt;FONT face="courier new,courier"&gt;sig1dig&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;sig2dig&lt;/FONT&gt;, etc. and corresponding formats.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 13:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/953374#M372475</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-12-12T13:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to round to 3 significant figures for this specific presentation?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/953377#M372476</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks, this is an amazingly elegant solution for my use case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2024 14:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-round-to-3-significant-figures-for-this-specific/m-p/953377#M372476</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2024-12-12T14:25:38Z</dc:date>
    </item>
  </channel>
</rss>

