<?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: How to change the number into character format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262168#M51119</link>
    <description>&lt;P&gt;Then you're not telling us everything or did it wrong. Post proc contents as indicated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;, as well as your code and log.&lt;/P&gt;
&lt;P&gt;The demo below show's that this method works when the data is numeric as indicated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input value;
CharVar = put(Value, best.);
cards;
47989
680
31
681
187
5814
405
319
149
887
5100
4047
74
33
;
run;

proc print data=have;
run;

proc contents data=have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2016 18:51:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-07T18:51:44Z</dc:date>
    <item>
      <title>How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262140#M51108</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following number.&amp;nbsp; They are in numberic in SAS.&amp;nbsp; I would like to change them into Charateric format.&amp;nbsp; I would like to use Interger format.&amp;nbsp; How to use put statement?&amp;nbsp; The variable name is Value.&amp;nbsp;&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;47989&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;680&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;31&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;681&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;187&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;5814&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;405&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;319&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;149&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;887&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;5100&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;4047&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;74&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;33&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 07 Apr 2016 17:15:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262140#M51108</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2016-04-07T17:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262145#M51109</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;CharVar = put(Value, &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;best.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Tom&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 17:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262145#M51109</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2016-04-07T17:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262148#M51110</link>
      <description>&lt;P&gt;In light of your other post with the same data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;Please run PROC CONTENTS on the data set and show the results here.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 17:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262148#M51110</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-07T17:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262161#M51114</link>
      <description>&lt;P&gt;I use the code below, &amp;nbsp;It didn't work, I found all the cells are blank in CharVar,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;CharVar = put(Value, &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;best.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 18:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262161#M51114</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2016-04-07T18:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262168#M51119</link>
      <description>&lt;P&gt;Then you're not telling us everything or did it wrong. Post proc contents as indicated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;, as well as your code and log.&lt;/P&gt;
&lt;P&gt;The demo below show's that this method works when the data is numeric as indicated.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input value;
CharVar = put(Value, best.);
cards;
47989
680
31
681
187
5814
405
319
149
887
5100
4047
74
33
;
run;

proc print data=have;
run;

proc contents data=have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 18:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262168#M51119</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-07T18:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262169#M51120</link>
      <description>&lt;P&gt;I wrote the code below, please see my attachment. &amp;nbsp;All of the numbers are gone in Formatted_value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data NHSS6;&lt;BR /&gt;SET NHSS5;&lt;BR /&gt;if type in ('O','C','H') then formatted_value=put(value1,5.1);&lt;BR /&gt;if type in ('N','D') then formatted_value=put(value1,best.);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 19:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262169#M51120</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2016-04-07T19:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262171#M51122</link>
      <description>&lt;P&gt;It works for some, not all, which means your IF condition is specified incorrectly NOT the conversion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the conversion alone and you'll see it works. Fix your IF condition.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 19:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262171#M51122</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-07T19:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262188#M51131</link>
      <description>&lt;P&gt;Because you do not specify a length for the variable formatted_value it gets one assigned based on the first use, Put using 5.1 so the length is 5.&lt;/P&gt;
&lt;P&gt;The default behavior with the BEST. format creates a 12 character result that is RIGHT justified. So only the first 5 characters can be stored.&lt;/P&gt;
&lt;P&gt;If your value does not have more than 7 charaters to display with the BEST. format then it appears blank because only the first 5 are kept.&lt;/P&gt;
&lt;P&gt;Also if you have a large enough value you will get scientific notation.&lt;/P&gt;
&lt;P&gt;See this code for examples.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data junk;
   input type $ value1;
   if type in ('O','C','H') then formatted_value=put(value1,5.1);
   if type in ('N','D') then formatted_value=put(value1,best.);
   if type in ('N','D') then otherformatted_value=put(value1,best.);
datalines;
O 25
O 23456789
N 29 
N 1234567
;
run;


proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution is to place a LENGTH statement before the first attempt AND to left justify the results&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Length Formatted_Value $ 12. ;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; type in (&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'O'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'C'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'H'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; formatted_value= strip(put(value1,&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;5.1)&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;if&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt; type in (&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'N'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'D'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;&lt;FONT color="#0000ff" face="SAS Monospace" size="2"&gt;then&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt; formatted_value= strip(put(value1,&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;&lt;FONT color="#804040" face="SAS Monospace" size="2"&gt;best.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;&lt;FONT face="SAS Monospace" size="2"&gt;));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 20:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262188#M51131</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-07T20:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the number into character format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262199#M51134</link>
      <description>&lt;P&gt;Wow, you're super, Ballardw!&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2016 20:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-the-number-into-character-format/m-p/262199#M51134</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2016-04-07T20:57:52Z</dc:date>
    </item>
  </channel>
</rss>

