<?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: Numbers with a minimum of two decimal numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831693#M328697</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432942"&gt;@edag&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to write numbers with a minimum of two decimal numbers. For example:&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp; -&amp;gt; 1.00&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/2 -&amp;gt; 0.50&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/3 -&amp;gt; 0.3333333333&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/4 -&amp;gt; 0.25&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/5 -&amp;gt; 0.20&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which number format does it need for this in SAS? Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not how formats work.&amp;nbsp; You tell it the total number of characters and the MAXIMUM number of decimal places to display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Sep 2022 23:34:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-09-03T23:34:33Z</dc:date>
    <item>
      <title>Numbers with a minimum of two decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831692#M328696</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to write numbers with a minimum of two decimal numbers. For example:&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp; -&amp;gt; 1.00&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/2 -&amp;gt; 0.50&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/3 -&amp;gt; 0.3333333333&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/4 -&amp;gt; 0.25&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/5 -&amp;gt; 0.20&lt;/FONT&gt;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which number format does it need for this in SAS? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 22:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831692#M328696</guid>
      <dc:creator>edag</dc:creator>
      <dc:date>2022-09-03T22:37:50Z</dc:date>
    </item>
    <item>
      <title>Number format with minimum number of decimal places?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831672#M328729</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried several number formats, but none of them helped me with my problem.&lt;/P&gt;&lt;P&gt;I want a number format that gives a &lt;U&gt;minimum&lt;/U&gt; number of decimal places.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my example I want a number format with a minimum number of two decimal places:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp; ----&amp;gt; 1.00&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/2 ----&amp;gt; 0.50&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/3 ----&amp;gt; 0.3333333333&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/4 ----&amp;gt; 0.25&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/5 ----&amp;gt; 0.20&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any format that could do this?&lt;/P&gt;&lt;P&gt;I use SAS Enterprise Guide 8.2 (Update 5).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Bernd&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 17:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831672#M328729</guid>
      <dc:creator>edag</dc:creator>
      <dc:date>2022-09-03T17:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Numbers with a minimum of two decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831693#M328697</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432942"&gt;@edag&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to write numbers with a minimum of two decimal numbers. For example:&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp; -&amp;gt; 1.00&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/2 -&amp;gt; 0.50&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/3 -&amp;gt; 0.3333333333&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/4 -&amp;gt; 0.25&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&lt;FONT face="courier new,courier"&gt;1/5 -&amp;gt; 0.20&lt;/FONT&gt;&lt;/P&gt;
&lt;P class="lia-align-justify"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which number format does it need for this in SAS? Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is not how formats work.&amp;nbsp; You tell it the total number of characters and the MAXIMUM number of decimal places to display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 23:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831693#M328697</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-03T23:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: Numbers with a minimum of two decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831694#M328698</link>
      <description>&lt;P&gt;Sure, with "maximum" it would be easy. But for a special problem I need the "minimum", and I hope there is a solution for this.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 23:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831694#M328698</guid>
      <dc:creator>edag</dc:creator>
      <dc:date>2022-09-03T23:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Numbers with a minimum of two decimal numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831696#M328699</link>
      <description>&lt;P&gt;Do you need a FORMAT or are you just making a report?&amp;nbsp; If the later then use IF/THEN logic to decide which format to use.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do d=1 to 5 ;
    x=1/d ;
    if mod(x,0.01) then put d= x= best12.;
    else put d= x=12.2 ;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;d=1 x=1.00
d=2 x=0.50
d=3 x=0.3333333333
d=4 x=0.25
d=5 x=0.20
&lt;/PRE&gt;
&lt;P&gt;If you need a format then use PROC FCMP to build a function that you can call in a format.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2403-2018.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2403-2018.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 00:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831696#M328699</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-04T00:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Number format with minimum number of decimal places?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831755#M328730</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/432942"&gt;@edag&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried several number formats, but none of them helped me with my problem.&lt;/P&gt;
&lt;P&gt;I want a number format that gives a &lt;U&gt;minimum&lt;/U&gt; number of decimal places.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my example I want a number format with a minimum number of two decimal places:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1&amp;nbsp;&amp;nbsp; ----&amp;gt; 1.00&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/2 ----&amp;gt; 0.50&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/3 ----&amp;gt; 0.3333333333&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/4 ----&amp;gt; 0.25&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;1/5 ----&amp;gt; 0.20&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any format that could do this?&lt;/P&gt;
&lt;P&gt;I use SAS Enterprise Guide 8.2 (Update 5).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;Bernd&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that the tool you use to edit and submit SAS code does not matter. What might matter is the version of SAS that your Enterprise Guide program is connecting to to run the SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there is no SAS defined format that will behave in that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you want this?&amp;nbsp; What is the purpose?&amp;nbsp; If you need to create those strings then perhaps it would be better to store them into a new character variable instead of trying to create a format that will display the numbers in that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do d=1 to 5;
    number = 1/d;
    if mod(number,0.01) = 0 then string = put(number,12.2);
    else string=put(number,best12.);
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;OBS    d     number       string

 1     1    1.00000            1.00
 2     2    0.50000            0.50
 3     3    0.33333    0.3333333333
 4     4    0.25000            0.25
 5     5    0.20000            0.20
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 03:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831755#M328730</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-05T03:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Number format with minimum number of decimal places?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831763#M328735</link>
      <description>&lt;P&gt;Thanks to all.&lt;BR /&gt;Those are prices in Euros and Cents. Most of them are prices like 23 Euros 20 Cent. This should be shown not at 23.2, but as 23.20, because in our company everyone wants it like this. But for some reasons there are also a few prices like 17 Euros and 14.33333 Cent. (Actually it's prices per year divided through 12, so this can sometimes happen.) This should be shown not as 17.14, because information would be missing, but as 17.1433333333.&lt;BR /&gt;Creating another format is no option because it is not THAT important and many other people use this database as well, so explaining this to them (and always having to load this new format) would be too difficult.&lt;BR /&gt;Making strings out of it is also no option because those variables are numbers and we have to calculate with them, add them, make a sum, etc.&lt;BR /&gt;Using 23.2000000000 and 17.1433333333 would technically be an option, but looks weird and overloaded.&lt;BR /&gt;We just hoped we could get rid of those silly 23.2 numbers. I was told "please make 23.20 out of it, everything else should stay the same".&lt;BR /&gt;All other variables in Euros and Cent are like 23.20, only this one is different.&lt;BR /&gt;In case there is no built-in function in SAS for this, it doesn't make sense.&lt;BR /&gt;Again thanks to all.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 07:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831763#M328735</guid>
      <dc:creator>edag</dc:creator>
      <dc:date>2022-09-05T07:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Number format with minimum number of decimal places?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831829#M328773</link>
      <description>&lt;P&gt;What you want is just not how SAS formats work. But you can always create a custom format and IF you are someone who can amend the autoexec then you can make such formats available environment wide.&lt;/P&gt;
&lt;P&gt;For what you need it would require a custom function that gets used within a custom format. Such constructs allow to implement data step level if/then functionality as part of a SAS format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In below example if you would want to provide such a custom format you would need to store the custom function and custom format in a permanent library (one of job) and then add the custom function library and custom format library to the environment (autoexec, options cmplib and append in code below). Once you do this you can add the format permanently to the table and whoever uses the table will print the data using the format you "attached" ...as long as they create a SAS session that also adds the function and format library (=creates the session using the autoexec where you defined these).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options dlcreatedir;
libname perm "%sysfunc(pathname(work))/perm";

option CMPLIB=perm.funcs;
options append=(fmtsearch=perm);

proc fcmp outlib=perm.funcs.demo;
  function f_min_two_dec(val_num) $;
    length val_char $16;
    if int(val_num*100)=val_num*100 then val_char=put(val_num,f32.2);
    else val_char=put(val_num,best32.);
    return(val_char);
  endsub;
  run;


proc format lib=perm;
  value min_two_dec(default=17)
  other=[f_min_two_dec()]
  ;
run;

data test;
  format a min_two_dec.;
  a=14.222229;output;
  a=14; output;
  a=14.1; output;
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-1662393835075.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74991i3B2C8EE08F8D7172/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1662393835075.png" alt="Patrick_0-1662393835075.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 16:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831829#M328773</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-05T16:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Number format with minimum number of decimal places?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831839#M328780</link>
      <description>&lt;P&gt;In that case the simplest answer is to just use the BEST format and leave it at that.&amp;nbsp; That is recognizable to humans.&amp;nbsp; There is no need to tell a human 1 euro per unit is the same as 1.00 euro per unit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But there are probably other issues you need to address.&amp;nbsp; What ever method you use to represent a number like 1/3 that cannot be expressed exactly as a binary number will be non-exact.&amp;nbsp; So you need to know how many decimal places will be used by the algorithms that use those numbers.&amp;nbsp; Then just display ALL of the values to that number of decimal places.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 17:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numbers-with-a-minimum-of-two-decimal-numbers/m-p/831839#M328780</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-09-05T17:21:25Z</dc:date>
    </item>
  </channel>
</rss>

