<?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: numeric to character using the input function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766671#M242999</link>
    <description>It's confusing though, just use the single PUT to get what you need, why the INPUT() again? &lt;BR /&gt;The INPUT doesn't do anything.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 08 Sep 2021 18:57:48 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-09-08T18:57:48Z</dc:date>
    <item>
      <title>numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766659#M242990</link>
      <description>&lt;P&gt;SAS documentation states that the source variable for input() function must be character.&lt;/P&gt;&lt;P&gt;I just tried the input function with a numeric source and it worked - i got what i wanted to get.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had a numeric variable that i wanted to convert into a character variable that had a length of 40 so i did the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_char_var=input(original_num_var, $char40.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked but i wonder if this is bad practice and if yes, then why? What are the downsides of doing what I did.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766659#M242990</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2021-09-08T18:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766662#M242991</link>
      <description>&lt;P&gt;Formats convert values to text. Informats convert text to values.&lt;/P&gt;
&lt;P&gt;So if you want to convert your number to a character value use the PUT() function, not the INPUT() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you used a numeric value as the first argument to the INPUT() function and a character informat as the second argument the SAS data step compiler noticed the conflict so it automatically converted the number into a character string (you will see messages about that in the SAS log).&amp;nbsp; It will use the BEST12. format to do that.&amp;nbsp; &amp;nbsp;So you converted your number into a 12 character string (automatic conversion) and use the INPUT() function to convert that 12 character string into a 40 character string.&amp;nbsp; You then assigned the value to the variable new_char.&amp;nbsp; If NEW_CHAR was already defined then the value was either truncated or padded with spaces to fill its defined length.&amp;nbsp; If NEW_CHAR had not yet been defined then the data step compiler would make a guess that you wanted to define it as length $40 to match the width of the informat you used in the INPUT() function call.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you effective did:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length new_var $40;
new_char_var=put(original_num_var, best12.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766662#M242991</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-08T18:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766663#M242992</link>
      <description>&lt;P&gt;Did you notice the log message?&amp;nbsp; The number is converted to character then read with $CHAR which preserves leading spaces.&amp;nbsp; In general it makes you look like you don't know what you're doing.&amp;nbsp; There may be a scenario where it is exactly what you want to do but I can't think of one.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2021-09-08 132736.png" style="width: 880px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63398i00119974D56DCCCB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2021-09-08 132736.png" alt="Screenshot 2021-09-08 132736.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766663#M242992</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-09-08T18:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766665#M242994</link>
      <description>&lt;P&gt;the proper way of doing this is define the length of 40 at the beginning and then do&lt;/P&gt;&lt;P&gt;data out;&lt;/P&gt;&lt;P&gt;set in;&lt;/P&gt;&lt;P&gt;length new_char_var $40.;&lt;/P&gt;&lt;P&gt;new_char_var=put(original_num_var, 8. -L);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by doing new_char_var=compress(input(original_num_var, $char40.)); i get the exact same output&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>Wed, 08 Sep 2021 18:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766665#M242994</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2021-09-08T18:44:23Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766666#M242995</link>
      <description>&lt;P&gt;Because SAS is fixing it for you behind the scenes, which is why the log is different if you do it correctly versus doing it the original way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766666#M242995</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-08T18:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766667#M242996</link>
      <description>&lt;P&gt;is the following more palatable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;new_char_var=INPUT(PUT(original_num_var, 8. -L), $CHAR40.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:51:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766667#M242996</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2021-09-08T18:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766669#M242997</link>
      <description>What does the log show?</description>
      <pubDate>Wed, 08 Sep 2021 18:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766669#M242997</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-08T18:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766670#M242998</link>
      <description>&lt;P&gt;the log is clean.. no error messages or warnings&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766670#M242998</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2021-09-08T18:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766671#M242999</link>
      <description>It's confusing though, just use the single PUT to get what you need, why the INPUT() again? &lt;BR /&gt;The INPUT doesn't do anything.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Sep 2021 18:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766671#M242999</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-08T18:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766673#M243000</link>
      <description>&lt;P&gt;the length needs to be 40 and i want to avoid specifying the length in a separate line. So converting numeric with lenght 8 into character with length 8 and then applying $char40. to make the length 40.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there a way to do that with a single put?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 19:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766673#M243000</guid>
      <dc:creator>K_S</dc:creator>
      <dc:date>2021-09-08T19:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: numeric to character using the input function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766675#M243002</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127053"&gt;@K_S&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;the length needs to be 40 and &lt;STRONG&gt;i want to avoid specifying the length in a separate line&lt;/STRONG&gt;. So converting numeric with lenght 8 into character with length 8 and then applying $char40. to make the length 40.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is there a way to do that with a single put?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's an artificial requirement that really makes no sense. It means you start breaking the typical coding structure and your code is unclear but if that's what you want go for it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Sep 2021 19:19:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/numeric-to-character-using-the-input-function/m-p/766675#M243002</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-08T19:19:56Z</dc:date>
    </item>
  </channel>
</rss>

