<?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 Format numeric column with max length of 12 and 2 decimal places in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496983#M6245</link>
    <description>&lt;P&gt;I need to have one numeric column &lt;STRONG&gt;newvar&lt;/STRONG&gt; with&amp;nbsp;max length of 12 and 2 decimal places&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;CREATE TABLE newtable AS&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (CASE&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHEN oldvar=1 THEN oldvar2 *&amp;nbsp;123.45&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHEN oldvar=2 THEN oldvar2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; END)&amp;nbsp;newvar&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;FROM oldtable;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;I've tried with&amp;nbsp;&lt;STRONG&gt;newvar&lt;/STRONG&gt; format=12.2 and DECIMAL(&lt;SPAN&gt;oldvar *&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;123.45,12,2&lt;/SPAN&gt;) with no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Sep 2018 15:08:38 GMT</pubDate>
    <dc:creator>valentina2095</dc:creator>
    <dc:date>2018-09-19T15:08:38Z</dc:date>
    <item>
      <title>Format numeric column with max length of 12 and 2 decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496983#M6245</link>
      <description>&lt;P&gt;I need to have one numeric column &lt;STRONG&gt;newvar&lt;/STRONG&gt; with&amp;nbsp;max length of 12 and 2 decimal places&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;CREATE TABLE newtable AS&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;SELECT&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (CASE&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHEN oldvar=1 THEN oldvar2 *&amp;nbsp;123.45&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;WHEN oldvar=2 THEN oldvar2&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; END)&amp;nbsp;newvar&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;FROM oldtable;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;I've tried with&amp;nbsp;&lt;STRONG&gt;newvar&lt;/STRONG&gt; format=12.2 and DECIMAL(&lt;SPAN&gt;oldvar *&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;123.45,12,2&lt;/SPAN&gt;) with no success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 15:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496983#M6245</guid>
      <dc:creator>valentina2095</dc:creator>
      <dc:date>2018-09-19T15:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Format numeric column with max length of 12 and 2 decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496994#M6246</link>
      <description>&lt;P&gt;You are not creating a new dataset with that statement:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select case when oldvar=1 then oldvar * 123.45
              when oldvar=2 then oldvar end as newvar format=12.2
  from   oldtable;
quit;
                     &lt;/PRE&gt;
&lt;P&gt;In the table want, you will see newvar with the format applied.&amp;nbsp; Do note you have no else, so anything other than 1 or 2 will be ignored.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Sep 2018 14:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496994#M6246</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-19T14:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Format numeric column with max length of 12 and 2 decimal places</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496996#M6247</link>
      <description>&lt;P&gt;Describe what you mean by "no success"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not need, or likely want parentheses around a case statement; any assignment in a SELECT statement should have AS varname so SQL knows what variable to assign the value to.&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
   SELECT
      CASE
         WHEN oldvar=1 THEN oldvar * 123.45
         WHEN oldvar=2 THEN oldvar
      END as newvar format=12.2
   FROM oldtable;
QUIT;&lt;/PRE&gt;
&lt;P&gt;But the value 123.45 is not going to be much of a test for 12.2 format. A format is not necessarily going to pad the displayed length to 12 characters if the value uses fewer character positions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this shows that the format is applied and the decimal portion of the display only uses 2 decimal positions and rounds the result to fit:&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
   SELECT
      CASE
         WHEN oldvar=1 THEN oldvar * 123456.876543
         WHEN oldvar=2 THEN oldvar
      END as newvar format=12.2
   FROM oldtable;
QUIT;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Sep 2018 14:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Format-numeric-column-with-max-length-of-12-and-2-decimal-places/m-p/496996#M6247</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-19T14:49:49Z</dc:date>
    </item>
  </channel>
</rss>

