<?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 convert numeric to char in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970274#M377057</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I wan to convert numeric to char.&lt;/P&gt;
&lt;P&gt;I want to see 2 figures after point&lt;/P&gt;
&lt;P&gt;&amp;nbsp;so see&amp;nbsp;0.18&amp;nbsp; and not&amp;nbsp;0.1818181818&lt;/P&gt;
&lt;P&gt;what is the way to do it pls?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x w;
cards;
10 20
5 10
2 11
;
run;

data want;
set have;
z=x/w;
z_char=put(z,best.);
format z 8.2;
run;
/*0.1818181818*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Jul 2025 12:13:06 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2025-07-06T12:13:06Z</dc:date>
    <item>
      <title>convert numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970274#M377057</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I wan to convert numeric to char.&lt;/P&gt;
&lt;P&gt;I want to see 2 figures after point&lt;/P&gt;
&lt;P&gt;&amp;nbsp;so see&amp;nbsp;0.18&amp;nbsp; and not&amp;nbsp;0.1818181818&lt;/P&gt;
&lt;P&gt;what is the way to do it pls?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x w;
cards;
10 20
5 10
2 11
;
run;

data want;
set have;
z=x/w;
z_char=put(z,best.);
format z 8.2;
run;
/*0.1818181818*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jul 2025 12:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970274#M377057</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-07-06T12:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: convert numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970275#M377058</link>
      <description>&lt;P&gt;If you change&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z_char=put(z,best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z_char=put(z,8.2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then z_char will display what you want.&amp;nbsp; Assuming this statement is the first reference to z_char, it will be an 8-byte character variable.&amp;nbsp; It will also be right justified, and with two decimal places.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may not want it to be right justified, in which case, you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z_char=left(put(z,8.2));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But remember that if you left justify the character value, then sorting by z_char may not generate the same order as sorting by z (i.e. '11.18&amp;nbsp; &amp;nbsp;' would precede '6.18&amp;nbsp; &amp;nbsp; ').&lt;/P&gt;
&lt;P&gt;--- Lexicographic ordering.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 14:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970275#M377058</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2025-07-07T14:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: convert numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970276#M377059</link>
      <description>&lt;P&gt;You can use VVALUE to retrieve the formatted representation of a variable's value using the actively associated format.&lt;/P&gt;
&lt;P&gt;Did you know you can specify -L on a format to indicate left justification?&lt;/P&gt;
&lt;PRE&gt;data _null_; 
  x = 1/3;
  y = x ;
  format x 8.2 y 8.2&lt;STRONG style="background-color: yellow;"&gt;-L&lt;/STRONG&gt; ;
  x_char = vvalue(x) ;
  y_char = vvalue(y) ;
  put '!' x_char $CHAR10. ;
  put '!' y_char $CHAR10. ;
run ;&lt;/PRE&gt;
&lt;P&gt;Log&lt;/P&gt;
&lt;PRE&gt;!    0.33     &amp;lt;--- x_char
!0.33         &amp;lt;--- y_char&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jul 2025 14:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970276#M377059</guid>
      <dc:creator>RichardAD</dc:creator>
      <dc:date>2025-07-06T14:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: convert numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970277#M377060</link>
      <description>&lt;P&gt;Why did you ask SAS to&amp;nbsp; PRINT the values of Z using the 8.2 format but then ask it to create Z_CHAR using the BEST. format?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember that a FORMAT is instructions for how to convert values into text.&amp;nbsp; It does not change how the value is stored, just how it is displayed.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jul 2025 17:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970277#M377060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-06T17:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: convert numeric to char</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970284#M377062</link>
      <description>&lt;P&gt;So you want truncate it or round it .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you want round it :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x w;
cards;
10 20
5 10
2 11
;
run;

data want;
set have;
z=x/w;
z_char=put(z,12.2 -l);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want truncate it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x w;
cards;
10 20
5 10
2 11
;
run;

proc format;
picture fmt
low-high='0009.99'
;
run;
data want;
set have;
z=x/w;
z_char=put(z,fmt. -l);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 01:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-numeric-to-char/m-p/970284#M377062</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-07-07T01:10:06Z</dc:date>
    </item>
  </channel>
</rss>

