<?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: Converting numeric variable to character and add dollar sign in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546927#M151506</link>
    <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that there is likely very little reason to create a character variable for most uses. One real reason not to is that values do not sort as expected.&lt;/P&gt;
&lt;PRE&gt;data example;
   length x $ 15;
   x="$39.54";output;
   x="$1,000,000.00"; output;
run;

proc sort data=example;
  by x;
run;

proc print data=example;
run;&lt;/PRE&gt;
&lt;P&gt;which would imply that a million is less than 39.&lt;/P&gt;
&lt;P&gt;You could end up spending a lot of time playing with output to get things to appear the way you want in report and analysis procedures.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Mar 2019 15:52:53 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-28T15:52:53Z</dc:date>
    <item>
      <title>Converting numeric variable to character and add dollar sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546877#M151493</link>
      <description>Hi,&lt;BR /&gt;I have a SAS dataset that has a column AMT which is a numeric variable and has format 15.2 . I want to convert it to a character variable and also add a dollar sign. I did final_amt=put(AMT,dollar15.2) and it worked but is it the right way to do? Or is there any other correct way to do? I always thought the informat is to read the variable rather than to display but I am confused I am able to display in dollar format with informat.&lt;BR /&gt;&lt;BR /&gt;Any suggestions or insight is appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Thu, 28 Mar 2019 12:47:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546877#M151493</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2019-03-28T12:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric variable to character and add dollar sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546882#M151495</link>
      <description>&lt;P&gt;put() uses a format, &lt;EM&gt;in&lt;/EM&gt;put() uses an &lt;EM&gt;in&lt;/EM&gt;format. Your method is the correct way to do it.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 13:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546882#M151495</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-03-28T13:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric variable to character and add dollar sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546890#M151496</link>
      <description>&lt;P&gt;In terms of the syntax you did it correctly.&amp;nbsp; However, if you started with extremely large values, you may not have converted properly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS formats specify the entire width.&amp;nbsp; For example, 15.2 does NOT mean 15 digits before the decimal point, plus 2 digits after.&amp;nbsp; It means a total of 15 characters including digits before the decimal point, digits after, and the decimal point itself.&amp;nbsp; It also includes a negative sign if one is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data actually contains numbers as large as 1 trillion, then the width of 15 would not be enough when using a dollar15.2 format.&amp;nbsp; This number requires a width of 17:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;$1,222,333,444.00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The original format of 15.2 makes me think that you might need a width of 15 without the commas and dollar sign.&amp;nbsp; If that is the case, you would need a wider format when adding commas and a dollar sign, such as dollar19.2&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 13:29:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546890#M151496</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-28T13:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric variable to character and add dollar sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546892#M151497</link>
      <description>&lt;P&gt;If you just want to display the variable AMT as a dollar sign plus some numbers, assign a format to it. No need to create a new variable.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 13:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546892#M151497</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-28T13:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Converting numeric variable to character and add dollar sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546927#M151506</link>
      <description>&lt;P&gt;I agree with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;that there is likely very little reason to create a character variable for most uses. One real reason not to is that values do not sort as expected.&lt;/P&gt;
&lt;PRE&gt;data example;
   length x $ 15;
   x="$39.54";output;
   x="$1,000,000.00"; output;
run;

proc sort data=example;
  by x;
run;

proc print data=example;
run;&lt;/PRE&gt;
&lt;P&gt;which would imply that a million is less than 39.&lt;/P&gt;
&lt;P&gt;You could end up spending a lot of time playing with output to get things to appear the way you want in report and analysis procedures.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 15:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-numeric-variable-to-character-and-add-dollar-sign/m-p/546927#M151506</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-28T15:52:53Z</dc:date>
    </item>
  </channel>
</rss>

