<?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: PROC FCMP w.d. format issue in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960509#M83926</link>
    <description>&lt;P&gt;This is never true?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;IF lx&amp;gt;len THEN PUT "WARN&amp;amp;ING: LENGTH value too small to correctly print value"; /* Get length of integer part of value to check against planned len, issue warn if too great */&lt;/LI-CODE&gt;
&lt;P&gt;sig=3 lx=8 len=9&lt;/P&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Data Set WORK.TEST6"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="162.233px" class="r data"&gt;a=123456789012.34&lt;/TD&gt;
&lt;TD width="60px" class="data"&gt;b=1.23E11&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2025 11:21:30 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2025-02-28T11:21:30Z</dc:date>
    <item>
      <title>PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953085#M83794</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create a function in FCMP to convert a numeric to character and print to&amp;nbsp;&lt;EM&gt;s&amp;nbsp;&lt;/EM&gt;significant figures.&amp;nbsp; The function has three inputs, x - the numeric value, s - number of significant figures to be reported, l - number of figures to the right of the decimal point when printing (to allow decimal alignment when using different s.f. across different observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The function works but prints a w.d. format was too small to be printed note, I pulled all the code out into a dataset (test2) instead of the function and the note disappears.&amp;nbsp; Any idea where it comes from or how I could debug?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;While testing I found the issue comes only from the derivation of c and d and only for the first record in test.&amp;nbsp; Test2 is set to produce same output as variable c in Test1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
   a=2981248.76403; OUTPUT; a=1248.76403; OUTPUT; a=248.76403; OUTPUT;a=48.76403; output; a=8.76403;;OUTPUT;a=0.76403;;OUTPUT;a=0.076403;;OUTPUT;a=0.0076403;;OUTPUT;a=0.00076403;;OUTPUT;a=0.000076403;;OUTPUT;a=0.00007640387106801;;OUTPUT;
 RUN; 
         
proc fcmp outlib=work.funcs.test;
function sigdig(x,s,l) $200;
  length g e f $200;
  if x then do;
    a=floor(log10(abs(x)));    
    b=a-(s-1);
    c=round(x,10**(b));
    cc=compress(put(x, best32.));
    ccc=length(compress(scan(cc, 2, ".")));
    d=floor(log10(abs(c)));
    e=cat(compress(put(l, best.)),".");
    ee=2-d+(s-3);
    eee=if ccc&amp;gt;0 and ee&amp;gt;0 then min(ccc, ee)
     else ee;
    ff=if eee&amp;lt;=0 THEN l
      ELSE l+1+eee;
    f=cat(compress(put(ff, best.)),".",compress(put(eee, best.)));
    g=if eee&amp;lt;=0 then putn(c,e)
             else   putn(c,f);
  end;
  else do;
    e=cat(compress(put(l, best.)),".");
    g=putn(c,e);
  end;
  return(g);
endsub;
run;
options cmplib=work.funcs;
 
 data test1;
   SET test;                
   c=sigdig(a, 3, 8);       
   d=sigdig(a, 4, 8);       
   e=sigdig(a, 5, 8);       
   f=sigdig(a, 6, 8);       
   g=sigdig(a, 7, 8);       
   h=sigdig(a, 8, 8);
      RUN;
        
    
      
      data test2;
        set test (rename=(a=x));
        l=8;
        s=3;
  length g e f $200;
  if x then do;
    a=floor(log10(abs(x)));    
    b=a-(s-1);
    c=round(x,10**(b));
    cc=compress(put(x, best32.));
    ccc=length(compress(scan(cc, 2, ".")));
    d=floor(log10(abs(c)));
    e=cat(compress(put(l, best.)),".");
    ee=2-d+(s-3);
    if ccc&amp;gt;0 and ee&amp;gt;0 then eee=min(ccc, ee);
     else eee=ee;
    if eee&amp;lt;=0 THEN ff=l;
      ELSE ff=l+1+eee;
    f=cat(compress(put(ff, best.)),".",compress(put(eee, best.)));
    if eee&amp;lt;=0 then g=putn(c,e);
             else   g=putn(c,f);
  end;
  else do;
    e=cat(compress(put(l, best.)),".");
    g=putn(c,e);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologies for the messiness of the code, I was going round in circles while testing,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 08:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953085#M83794</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2024-12-10T08:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953086#M83795</link>
      <description>&lt;P&gt;First question: Why not simply use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n0mlfb88dkhbmun1x08qbh5xbs7e.htm" target="_self"&gt;Put Function&lt;/A&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 08:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953086#M83795</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2024-12-10T08:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953087#M83796</link>
      <description>&lt;P&gt;For the data in TEST, could you give the code to print to 3 significant figures?&lt;BR /&gt;As far as I can see I would need to use a different put statement for each line.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 08:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953087#M83796</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2024-12-10T08:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953097#M83797</link>
      <description>&lt;P&gt;Suggest you provide some sample data that also include a column with the desired result. This should remove a lot of ambiguity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't fully understand what you're after. For example: How many significant figures (digits?) has 100.0? And how would you want to display it if you're after sample code "&lt;SPAN&gt;&lt;EM&gt;to print to 3 significant figures&lt;/EM&gt;".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last set of digits in your sample represents a number that SAS can't store with full precision.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  attrib 
    a_num  length=8   format=best32. informat=best32. 
    a_char length=$32 format=$32.    informat=$32.;
  input @1 a_num @1 a_char;
  datalines;
2981248.76403
1248.76403
248.76403
48.76403
8.76403
0.76403
0.076403
0.0076403
0.00076403
0.000076403
0.00007640387106801
;
RUN;
proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1733835067229.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102868i41D46E62ACF1079E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1733835067229.png" alt="Patrick_0-1733835067229.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 12:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953097#M83797</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-12-10T12:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953101#M83798</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The last set of digits in your sample represents a number that SAS can't store with full precision.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1733835067229.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102868i41D46E62ACF1079E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1733835067229.png" alt="Patrick_0-1733835067229.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I think the internal precision is sufficient; it's just the BEST32. format rounding incorrectly in this case (whereas the E32. format shows all relevant digits).&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 14:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953101#M83798</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-12-10T14:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953104#M83799</link>
      <description>&lt;P&gt;Below is a print of TEST1y, based on the input dataset TEST, it rounds column A (numeric) to 3 significant figures in col C, 4s.f. in col D, 5s.f in col E, 6s.f in col F, 7s.f in col H&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="aa.jfif" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102870i43A42518F00FC5C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="aa.jfif" alt="aa.jfif" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The function is working as expected, it just produces a w.d. format note that I cannot reproduce when I use the same code in a datastep.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 14:44:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953104#M83799</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2024-12-10T14:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953106#M83800</link>
      <description>"print of TEST1y," should actually read "print of TEST1,"</description>
      <pubDate>Tue, 10 Dec 2024 14:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953106#M83800</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2024-12-10T14:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953110#M83802</link>
      <description>&lt;P&gt;I am going to make a style comment about your function.&lt;/P&gt;
&lt;P&gt;If I had inherited code with that function definition as shown my first reaction is "Why the !@#$!@#$!@# are there no comments at all?"&lt;/P&gt;
&lt;P&gt;The second is "Why does this exist? I have no way to tell why it is needed".&lt;/P&gt;
&lt;P&gt;Third is "Do I really have to spend a bunch of hours trying to figure out what each of these parameters is supposed to be for?"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any function should in the code include comments as an absolute minimum a description of the expected values for the input parameters. Such as "values must be integers". Since this is claiming to do something related formats then likely one of the parameters must be greater than 0 and less than 32 (whatever equivalent to W) . If the parameters have an interaction, such as W and D in formats (D must be &amp;lt; W) that should be stated. Better would be also include comments as why the function is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't spend a lot of time trying to parse the code but I am not sure which is the number of decimals and which is the number of significant digits. Which means I can't make a suggestion of where in your code you have to test the VALUE whether the number of significant digits makes sense or if the W in your PUTN calls is large enough. Hint: if the value is 1000 or greater W must be 4 or larger or Put or Putn will generate the " W.D format was too small for the number to be printed." &lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 15:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953110#M83802</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-10T15:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953137#M83804</link>
      <description>&lt;P&gt;If the error occurs in the calculation of C then can you explain the meaning of the value of C?&lt;/P&gt;
&lt;P&gt;While you are at it explain what the values of A and B, which are used to create C, are.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 20:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953137#M83804</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-10T20:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953138#M83805</link>
      <description>&lt;P&gt;What is CC?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.test;
function sigdig(x,s,l) $200;
  length g e f $200;
  if x then do;
    a=floor(log10(abs(x)));    
    b=a-(s-1);
    c=round(x,10**(b));
    cc=compress(put(x, best32.));
    ccc=length(compress(scan(cc, 2, ".")));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From the assignment statement it looks like you want it to be a character variable.&lt;/P&gt;
&lt;P&gt;But you did not set any length for it, like you did for G E and F.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you using COMPRESS() function there?&amp;nbsp; Did you mean to use the LEFT() function to remove the leading spaces? If so then just add the -L option to the format specification.&lt;/P&gt;
&lt;PRE&gt;392  data test;
393    x=2981248.76403;
394    string1=put(x,best32.);
395    string2=put(x,best32.-L);
396    format string: $quote. ;
397    put (_all_) (=/);
398  run;


x=2981248.764
string1="                   2981248.76403"
string2="2981248.76403"
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should clean up those and other similar things and see if the note goes away.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 20:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953138#M83805</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-10T20:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953148#M83806</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;Yes, you're right. No precision issue. Thanks for pointing that out.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/285012"&gt;@SwissC&lt;/a&gt;&amp;nbsp;Before writing the function I suggest you get data step code as clean as possible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what I understand there are two separate problems:&lt;/P&gt;
&lt;P&gt;1. How to create a number with the desired significant figures?&lt;/P&gt;
&lt;P&gt;2. How to display/print numbers?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you solved 1 already.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Point 2 is a bit harder. There isn't a format that does such alignment around a decimal point. The only way I can think of is to create a string (character variable) with leading spaces. But that won't be enough because you have then also to use a non-proportional (monospaced) typeset like Courier AND you need to ensure that the leading blanks are protected - and how to do this will depend on the output destination (like &amp;amp;nbsp; and/or the &amp;lt;pre&amp;gt; tag for HTML).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below sample code works for writing to the SAS log and should also work for listing output. Other output destinations will require additional work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  attrib 
  	char_value length=$32 informat=$32.
  	value  		 length=8   informat=best32. format=f32.31;
  input @1 char_value @1 value;
  datalines;
2981248.76403
1248.76403
248.76403
48.76403
8.76403
0.76403
0.076403
0.0076403
0.00076403
0.000076403
0.00007640387106801
-0.000076403
;
RUN;

%let sig_figures=3;
data rounded;
    set test;
    
    /** populate numerical variable with desired number of significan figures **/
    format SigFig_Value best32.;
    sig_figures=&amp;amp;sig_figures;
    /* Determine the number of significant figures */
    if value = 0 then SigFig_Value = 0;
    else SigFig_Value = round(value, 10**floor(log10(abs(value))-sig_figures+1));
    
    /** create character variable with leading blanks so decimal point is always at the same string position **/
    format char_SigFig_Value $char60.;
    char_SigFig_Value=put(SigFig_Value,best32. -l);
    char_SigFig_Value=cat(repeat(' ',18-length(scan(char_SigFig_Value,1,'.'))),char_SigFig_Value);
    
    /* write character variable to log where typeset is Courier */
		put char_SigFig_Value $char60.;
run;

/* proc print data=rounded noobs;  */
/* 	format char_SigFig_Value $char60.; */
/* run; */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1733868989628.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102881i2E509AC72873886B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1733868989628.png" alt="Patrick_0-1733868989628.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 22:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953148#M83806</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-12-10T22:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953151#M83807</link>
      <description>&lt;P&gt;That is useful.&amp;nbsp; The use of BEST to make the string causes issues however when the least significant of the digits is zero.&amp;nbsp; Which you can see with your example data when 8 significant are asked for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;           -2981248.8
            2981248.8
               1248.764
                248.76403
                 48.76403
                  8.76403
                  0.76403
                  0.076403
                  0.0076403
                  0.00076403
                  0.000076403
                  0.000076403871
                 -0.000076403
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It probably would be better to convert the number to an integer and then add back the decimal point (and possibly leading zeros) at the proper place.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if x then magnitude = 1+floor(log10(abs(x)));
  else magnitude=1;
  integer = round(x * 10**(sig_figures-magnitude));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Dec 2024 23:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953151#M83807</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-10T23:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953197#M83808</link>
      <description>&lt;P&gt;Your code seems needlessly complex. You should leverage the existing formats.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data VALUES;
  infile cards truncover;
  input VAL 32.;
cards;
         -2981248.8
            2981248.8
               1248.764
                248.76403
                 48.76403
                  8.76403
                  0.76403
                  0.076403
                  0.0076403
                  0.00076403
                  0.000076403
                  0.000076403871
                 -0.000076403
; 

data TEST;
  set VALUES;
  SIG = 3;
  E   = putn(VAL, cats('E', SIG+6, '.'));
  NUM = input(E, 32.);
run;
  
proc print;
  format _NUMERIC_ best32.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Table WORK.NOFCT"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs.&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;VAL&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;SIG&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;E&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;NUM&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-2981248.8&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-2.98E+06&lt;/TD&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-2980000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;2981248.8&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data"&gt;2.98E+06&lt;/TD&gt;
&lt;TD class="r data"&gt;2980000&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;1248.764&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data"&gt;1.25E+03&lt;/TD&gt;
&lt;TD class="r data"&gt;1250&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;248.76403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data"&gt;2.49E+02&lt;/TD&gt;
&lt;TD class="r data"&gt;249&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;48.76403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data"&gt;4.88E+01&lt;/TD&gt;
&lt;TD class="r data"&gt;48.8&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="r data"&gt;8.76403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data"&gt;8.76E+00&lt;/TD&gt;
&lt;TD class="r data"&gt;8.76&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="r data"&gt;0.76403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.64E-01&lt;/TD&gt;
&lt;TD class="r data"&gt;0.764&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="r data"&gt;0.076403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.64E-02&lt;/TD&gt;
&lt;TD class="r data"&gt;0.0764&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="r data"&gt;0.0076403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.64E-03&lt;/TD&gt;
&lt;TD class="r data"&gt;0.00764&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="r data"&gt;0.00076403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.64E-04&lt;/TD&gt;
&lt;TD class="r data"&gt;0.000764&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TD class="r data"&gt;0.000076403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.64E-05&lt;/TD&gt;
&lt;TD class="r data"&gt;0.0000764&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TD class="r data"&gt;0.000076403871&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.64E-05&lt;/TD&gt;
&lt;TD class="r data"&gt;0.0000764&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-0.000076403&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-7.64E-05&lt;/TD&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-0.0000764&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 10:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953197#M83808</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-12-11T10:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953201#M83809</link>
      <description>&lt;P&gt;Perhaps something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=WORK.FUNCS.TEST;
function sigdig(VAL, SIG, FMT $) $32;
  %* Input validation to be added;
  length E $32;
  E = putn(VAL, cats('E', SIG+6, '.'));
  if upcase(FMT)='E' then return(strip(E));
  else return(cat(input(E, 32.)));
endsub;
run;
options cmplib=WORK.FUNCS;  

data FCT;
  set VALUES;
  NUM1 = sigdig(VAL, 4, 'S');
  NUM2 = sigdig(VAL, 4, 'E');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Table WORK.FCT"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs.&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;VAL&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;NUM1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;NUM2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-2981248.8&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-2981000&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-2.981E+06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;2981248.8&lt;/TD&gt;
&lt;TD class="data"&gt;2981000&lt;/TD&gt;
&lt;TD class="data"&gt;2.981E+06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;1248.764&lt;/TD&gt;
&lt;TD class="data"&gt;1249&lt;/TD&gt;
&lt;TD class="data"&gt;1.249E+03&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;248.76403&lt;/TD&gt;
&lt;TD class="data"&gt;248.8&lt;/TD&gt;
&lt;TD class="data"&gt;2.488E+02&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;48.76403&lt;/TD&gt;
&lt;TD class="data"&gt;48.76&lt;/TD&gt;
&lt;TD class="data"&gt;4.876E+01&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="r data"&gt;8.76403&lt;/TD&gt;
&lt;TD class="data"&gt;8.764&lt;/TD&gt;
&lt;TD class="data"&gt;8.764E+00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="r data"&gt;0.76403&lt;/TD&gt;
&lt;TD class="data"&gt;0.764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-01&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="r data"&gt;0.076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.0764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-02&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="r data"&gt;0.0076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.00764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-03&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="r data"&gt;0.00076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-04&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TD class="r data"&gt;0.000076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.0000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TD class="r data"&gt;0.000076403871&lt;/TD&gt;
&lt;TD class="data"&gt;0.0000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-0.000076403&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-0.0000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-7.640E-05&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 11:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953201#M83809</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-12-11T11:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953214#M83810</link>
      <description>&lt;P&gt;Or this if you want to ensure the display of all digits (see report lines 4 and 14).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data VALUES;
  infile cards truncover;
  input VAL 32.;
cards;
         -2981248.8
            2981248.8
               1248.764
                248.076403
                 48.76403
                  8.76403
                  0.76403
                  0.076403
                  0.0076403
                  0.00076403
                  0.000076403
                  0.000076403871
                 -0.000076403
                 -0.000076403
                  1
; 
  
proc fcmp outlib=WORK.FUNCS.TEST;
function sigdig(VAL, SIG, FMT $) $32;
  %* Input validation to be added;
  length E F $32;
  E = putn(VAL, cats('E', SIG+6, '.'));
  if upcase(FMT)='E' then return(strip(E));
  else do;
    F = cat(input(E, 32.));
    L = length(F); 
    if L &amp;lt; SIG then F = cats(F,'.',repeat('0',SIG-L-1)); 
    return(strip(F));
  end;  
endsub;
run;
options cmplib=WORK.FUNCS;  

data FCT;
  set VALUES;
  NUM1 = sigdig(VAL, 4, 'S');
  NUM2 = sigdig(VAL, 4, 'E');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Table WORK.FCT"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs.&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;VAL&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;NUM1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;NUM2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-2981248.8&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-2981000&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-2.981E+06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r data"&gt;2981248.8&lt;/TD&gt;
&lt;TD class="data"&gt;2981000&lt;/TD&gt;
&lt;TD class="data"&gt;2.981E+06&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r data"&gt;1248.764&lt;/TD&gt;
&lt;TD class="data"&gt;1249&lt;/TD&gt;
&lt;TD class="data"&gt;1.249E+03&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r data"&gt;248.0076403&lt;/TD&gt;
&lt;TD class="data"&gt;248.0&lt;/TD&gt;
&lt;TD class="data"&gt;2.480E+02&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r data"&gt;48.76403&lt;/TD&gt;
&lt;TD class="data"&gt;48.76&lt;/TD&gt;
&lt;TD class="data"&gt;4.876E+01&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;6&lt;/TH&gt;
&lt;TD class="r data"&gt;8.76403&lt;/TD&gt;
&lt;TD class="data"&gt;8.764&lt;/TD&gt;
&lt;TD class="data"&gt;8.764E+00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;7&lt;/TH&gt;
&lt;TD class="r data"&gt;0.76403&lt;/TD&gt;
&lt;TD class="data"&gt;0.764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-01&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;8&lt;/TH&gt;
&lt;TD class="r data"&gt;0.076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.0764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-02&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;9&lt;/TH&gt;
&lt;TD class="r data"&gt;0.0076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.00764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-03&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;10&lt;/TH&gt;
&lt;TD class="r data"&gt;0.00076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-04&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;11&lt;/TH&gt;
&lt;TD class="r data"&gt;0.000076403&lt;/TD&gt;
&lt;TD class="data"&gt;0.0000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;12&lt;/TH&gt;
&lt;TD class="r data"&gt;0.000076403871&lt;/TD&gt;
&lt;TD class="data"&gt;0.0000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;7.640E-05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;13&lt;/TH&gt;
&lt;TD class="r data" style="white-space: nowrap;"&gt;-0.000076403&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-0.0000764&lt;/TD&gt;
&lt;TD class="data" style="white-space: nowrap;"&gt;-7.640E-05&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;14&lt;/TH&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="data"&gt;1.000&lt;/TD&gt;
&lt;TD class="data"&gt;1.000E+00&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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>Wed, 11 Dec 2024 12:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/953214#M83810</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-12-11T12:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960164#M83918</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry it took me so long to come back to this, ended up with a job change and life turned a little hectic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are all right the original code was terrible and in completely the wrong direction.&amp;nbsp; I learnt my lesson not to grab random code from the internet and start to hack it to pieces late on a Friday afternoon&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To those of you who mentioned using the E format, thank you very much, using this did not even cross my mind (not sure I have ever used this format before).&amp;nbsp; Your various suggestions were most helpful.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;I recreated the function as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
a=9999999.76403; OUTPUT;
a=2981248.76403; OUTPUT;
a=981248.76403; OUTPUT; 
a=81248.76403; OUTPUT;
a=0.9999999999; OUTPUT; 
a=9.98999; OUTPUT;
a=9.99999; OUTPUT; 
a=12.76; OUTPUT; 
a=2.76; OUTPUT; 
a=12.7602; OUTPUT; 
a=1248.76403; OUTPUT; 
a=248.76403; OUTPUT;
a=48.76403; output; 
a=8.76403; OUTPUT;
a=0.76403; OUTPUT;
a=0.76003; OUTPUT;
a=0.076403; OUTPUT;
a=0.0076403; OUTPUT;
a=0.00076403; OUTPUT;
a=0.000076403; OUTPUT;
a=0.00007640387106801; OUTPUT;
RUN; 
DATA test;
 SET test;
 OUTPUT;
 a=a*-1;
 OUTPUT;
RUN;
PROC SORT data=test; BY descending a; RUN;

proc fcmp outlib=WORK.FUNCS.TEST;
function sigdigz(val, sig, len) $200;
  
  LENGTH as_e as_t  rhs wd outval $200;                                         /* Set lengths for variables */
  %LET ING=ING;
  
  as_e = putn(val, cats('E', SIG+6, '.'));                                      /* Print value using E notation */
  as_t = put(val, best32.);                                                     /* Print value in full */

  rhs=scan(as_e, 2, "E");                                                       /* Get text from right hand side of E notation */
  e=input(rhs, best.);                                                          /* And convert to numeric */
  maxd=length(scan(as_t, 2, "."));                                              /* Find maximum number of decimal places in original value */

  IF e+1&amp;lt;sig THEN d=min(sig-e-1, maxd);                                         /* d will be number of values to display after decimal point, but cannot be more than original value */
   else d=0;
  IF d=0 THEN w=len;                                                            /* w is width of format, based on len and expanded for decimal values */
    ELSE w=len+2+d;
  wd=compress(put(w, best.)||"."||put(d, best.));                               /* create format for printing value */
 
  as_n=input(as_e, E32.);                                                       /* Input E text value as numeric */ 
  outval=putn(as_n, wd);                                                        /* and print to text using format created above */
  
  lx=len-length(scan(compress(outval), 1, "."));                                /* Get length of integer part of value to check against planned len, issue warn if too great */          
  
  IF lx&amp;gt;len THEN PUT "WARN&amp;amp;ING: LENGTH value too small to correctly print value";

  return(outval);
endsub;
run;
options cmplib=WORK.FUNCS;  

DATA test6;
   SET test;
   c=sigdigz(a, 3, 9);       
   d=sigdigz(a, 4, 9);       
   e=sigdigz(a, 5, 9);       
   f=sigdigz(a, 6, 9);       
   g=sigdigz(a, 7, 9);       
   h=sigdigz(a, 8, 9);
RUN;

proc print data=test6; format a best32.;run;&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;The function now works as intended such that,&lt;/P&gt;
&lt;P&gt;- All numbers are decimal aligned according the len value (characters prior to the decimal point)&lt;/P&gt;
&lt;P&gt;- Trailing zeros are correctly kept (e.g. 0.76003 to 4s.f. is 0.7600, the trailing zero are shown as we know the value was captured with this precision)&lt;/P&gt;
&lt;P&gt;- Values are not over ?&lt;EM&gt;signified?&amp;nbsp;&lt;/EM&gt;(e.g. 2.76 to 4s.f is still 2.76, we cannot assign this to 2.760 as that would be presenting to a higher precision than we actually know).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2025 16:20:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960164#M83918</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2025-02-25T16:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960509#M83926</link>
      <description>&lt;P&gt;This is never true?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;IF lx&amp;gt;len THEN PUT "WARN&amp;amp;ING: LENGTH value too small to correctly print value"; /* Get length of integer part of value to check against planned len, issue warn if too great */&lt;/LI-CODE&gt;
&lt;P&gt;sig=3 lx=8 len=9&lt;/P&gt;
&lt;TABLE class="table" style="border-spacing: 0;" aria-label="Data Set WORK.TEST6"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="162.233px" class="r data"&gt;a=123456789012.34&lt;/TD&gt;
&lt;TD width="60px" class="data"&gt;b=1.23E11&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 11:21:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960509#M83926</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-02-28T11:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: PROC FCMP w.d. format issue</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960510#M83927</link>
      <description>&lt;P&gt;You are right I think it should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;  lx=length(scan(compress(outval), 1, "."));                                /* Get length of integer part of value to check against planned len, issue warn if too great */          
  
  IF lx&amp;gt;len THEN PUT "WARN&amp;amp;ING: LENGTH value too small to correctly print value";&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 11:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/PROC-FCMP-w-d-format-issue/m-p/960510#M83927</guid>
      <dc:creator>SwissC</dc:creator>
      <dc:date>2025-02-28T11:50:24Z</dc:date>
    </item>
  </channel>
</rss>

