<?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: Format Numeric Values to Retain Trailing Zeroes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761008#M240732</link>
    <description>&lt;P&gt;Statements like this don't make much sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOT_OBESE = put(NOT_OBESE, f6.3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is NOT_OBSESE a character variable or a numeric variable?&lt;/P&gt;
&lt;P&gt;If it is character why are you using PUT() function to format it using a numeric format instead of a character format?&lt;/P&gt;
&lt;P&gt;If it is numeric why are you assigning it a character string value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would make more sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOT_OBESE_string = put(NOT_OBESE, f6.3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Aug 2021 20:35:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-11T20:35:45Z</dc:date>
    <item>
      <title>Format Numeric Values to Retain Trailing Zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761001#M240730</link>
      <description>&lt;P&gt;My data is like such:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mariko5797_0-1628712293316.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62485i4D6BF4BA1F68041C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mariko5797_0-1628712293316.png" alt="mariko5797_0-1628712293316.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;My code is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data contdem; 
 set contdem;
 if _STAT_ in ('MEAN', 'MED') then do;
 ALL= put(ALL, f6.3);
 NOT_OBESE = put(NOT_OBESE, f6.3);
 OBESE = put(OBESE, f6.3);
 SEVERELY_OBESE = put(SEVERELY_OBESE, f6.3);
end;
else if _STAT_ = 'MIN' | _STAT_ = 'MAX' then do;
 ALL= put(ALL, f5.2);
 NOT_OBESE = put(NOT_OBESE, f5.2);
 OBESE = put(OBESE, f5.2);
 SEVERELY_OBESE = put(SEVERELY_OBESE, f5.2);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Perhaps I don't know what this format does, but I essentially want the mean and median to be always go out to 3 decimals and the minimum and maximum to always go out to 2 decimals. However, when I run this code, only some of the decimals go out to 3 or 2. For instance, max age 50 turns to 50.00 but max height 177.2 stays as 177.2 instead of 177.20.&lt;/P&gt;
&lt;P&gt;Can someone help? Thank you in advance&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:19:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761001#M240730</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-08-11T20:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: Format Numeric Values to Retain Trailing Zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761008#M240732</link>
      <description>&lt;P&gt;Statements like this don't make much sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOT_OBESE = put(NOT_OBESE, f6.3);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is NOT_OBSESE a character variable or a numeric variable?&lt;/P&gt;
&lt;P&gt;If it is character why are you using PUT() function to format it using a numeric format instead of a character format?&lt;/P&gt;
&lt;P&gt;If it is numeric why are you assigning it a character string value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would make more sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOT_OBESE_string = put(NOT_OBESE, f6.3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761008#M240732</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-11T20:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Format Numeric Values to Retain Trailing Zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761017#M240736</link>
      <description>&lt;P&gt;SAS Formats are applied to Variables, not rows of values. One format per variable.&lt;/P&gt;
&lt;P&gt;Since your requirement is per Statistic, then you cannot apply format per row and either have to 1) restructure the data set so that the variables that indicate the statistic are part of the column, or 2) settle for some approach that is applied at the time humans look at the values such as report text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a data set that is used to create that one you might be able to create report that reads the way you expect, maybe. Depends on what you really need.&lt;/P&gt;
&lt;P&gt;Example using a data set you should have available to test code.&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=sashelp.class;
   class sex;
   var age height weight;
   table (age height weight) *(mean*f=7.3 std*f=8.4 max*f=6.2 n ),
         all='All' sex=' '
   ;
run;&lt;/PRE&gt;
&lt;P&gt;I hope you can see where the format is specified using the &amp;lt;statistic&amp;gt;*f=&amp;lt;format&amp;gt;. I did not supply a format for N to show the default behavior.&lt;/P&gt;
&lt;P&gt;This procedure supports most of the common statistics (and a number of percentages).&lt;/P&gt;
&lt;P&gt;For a great many purposes the format assigned to a numeric value makes no difference until &lt;STRONG&gt;people&lt;/STRONG&gt; need to read it, which means a report, graph or the value in a table created by some procedure. Datasets, not so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "format" doesn't work because you are attempting to create Character values with Put into variables that are apparently numeric. SAS does maintain a difference between the two.&lt;/P&gt;
&lt;P&gt;Did you read your log a see a lot conversion notes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 21:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761017#M240736</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-11T21:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Format Numeric Values to Retain Trailing Zeroes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761055#M240757</link>
      <description>&lt;P&gt;First, i have to repeat, what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; already said:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;SAS Formats are applied to Variables, not rows of values. One format per variable.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Depending on what you want to do with the dataset afterwards, there could be a way to achieve what you want, but only by converting all numeric variables to char. When exporting such data as pdf or csv, the data type hardly matters.&lt;/P&gt;
&lt;P&gt;The following step is untested, because you haven't provided data in usable form.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have(rename= (all = num_all /* add rename for other vars */));
    length 
        format $ 32
        all $ 10 
    ;
    
    select (_stat_);
        when ('MEAN', 'MED') format = 'f6.3';
        when ('MIN', 'MAX') format = 'f5.2';
        otherwise format = ' ';
    end;
    
    if not missing(format) then do;
        all = putn(num_all, format);
        /* add other variables */
    end;
    else do;
        all = cats(num_all);
    end;
    
    drop format num_:;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Aug 2021 04:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-Numeric-Values-to-Retain-Trailing-Zeroes/m-p/761055#M240757</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-08-12T04:26:38Z</dc:date>
    </item>
  </channel>
</rss>

