<?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: Help to understand numeric-character-numeric conversion? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132660#M36078</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;As per your question :-&lt;/P&gt;&lt;P&gt;branch= input(put(branch,$2.),2.)&lt;/P&gt;&lt;P&gt;you are&lt;/P&gt;&lt;P&gt;1) converting numeric variable branch with format $2. to character and then&lt;/P&gt;&lt;P&gt;2) again you are converting this character to numeric variable which results in the same values as in source dataset.&lt;/P&gt;&lt;P&gt;in stead of writing that whole code , you can simply write as:&lt;/P&gt;&lt;P&gt; if branch ne . then branch1=branch;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Mar 2013 03:10:40 GMT</pubDate>
    <dc:creator>mano</dc:creator>
    <dc:date>2013-03-12T03:10:40Z</dc:date>
    <item>
      <title>Help to understand numeric-character-numeric conversion?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132658#M36076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;Hi SAS Forum,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;Could you please help me to understand this code piece. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;DATA&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; want;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;IF&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;PUT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;(BRANCH,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 11pt;"&gt;$2.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;) NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;' '&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BRANCH = INPUT(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;PUT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;(BRANCH,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 11pt;"&gt;$2.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;),2&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;.&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;);&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt; text-decoration: underline;"&gt;I take the first part of the above &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;IF&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;PUT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;(BRANCH,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 11pt;"&gt;$2.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;) NE &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;The meaning of this is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;“ A numeric variable named “Branch” is converted into a character variable with a length of $2. And if the value of the converted i"Branch" variable is not equal to missing” &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;Question 1.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;Is my interpretation correct?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;Question 2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;But $2. should be the initial state and not eventual state. How come the initial state of a numeric variable is $2.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;Question 3.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;What is the meaning of next segment which is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Branch&amp;nbsp; = INPUT(&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;PUT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;(Branch,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: teal; font-size: 11pt;"&gt;$2.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;),2&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;.&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;);&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Your help is appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;Mirisage &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 02:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132658#M36076</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2013-03-12T02:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help to understand numeric-character-numeric conversion?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132659#M36077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Code does not make sense.&amp;nbsp; There is no way to tell from that code fragment whether the original variable BRANCH read from the dataset HAVE is numeric or character. (or even which one the programmer thought it was supposed to be).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If Branch is numeric then you should not attempt to use a character format such as $2. with it.&amp;nbsp; SAS will give a warning that variable BRANCH is already defined as numeric.&amp;nbsp; It will then automatically adjust and use the numeric format 2. in the PUT() function calls. Even if you fix that then testing whether the character string generated by the PUT() function is blank does not make much sense.&amp;nbsp; Why not just test if the value of BRANCH is missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If Branch is character then you should not attempt to assign it the numeric value that the INPUT() function will generate when using the numeric informat 2. .&amp;nbsp; In that case if you want to truncate the string that is stored in BRANCH then just use SUBSTR() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question 1).&amp;nbsp; No.&amp;nbsp; To convert a numeric variable into a character string you could use the PUT() function, but you would use it with a numeric format.&lt;/P&gt;&lt;P&gt;Question 2)&amp;nbsp; Question does make any sense. There is no initial state here, the PUT() and INPUT() functions are just doing what the programmer tells them to do.&lt;/P&gt;&lt;P&gt;Question 3) There is no meaning. Because of the use of the PUT() function on a numeric variable with a character format it makes no sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did it come with any comments that explain what they were trying to do?&amp;nbsp; Can you tell from the rest of the original program?&lt;/P&gt;&lt;P&gt;Perhaps they want to read the two most significant digits of a number where the magnitude of the number varies widely?&amp;nbsp; If want the first two digits then why not use:&amp;nbsp; substr(left(put(branch,32.)),1,2)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 03:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132659#M36077</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-12T03:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help to understand numeric-character-numeric conversion?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132660#M36078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;As per your question :-&lt;/P&gt;&lt;P&gt;branch= input(put(branch,$2.),2.)&lt;/P&gt;&lt;P&gt;you are&lt;/P&gt;&lt;P&gt;1) converting numeric variable branch with format $2. to character and then&lt;/P&gt;&lt;P&gt;2) again you are converting this character to numeric variable which results in the same values as in source dataset.&lt;/P&gt;&lt;P&gt;in stead of writing that whole code , you can simply write as:&lt;/P&gt;&lt;P&gt; if branch ne . then branch1=branch;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Mar 2013 03:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132660#M36078</guid>
      <dc:creator>mano</dc:creator>
      <dc:date>2013-03-12T03:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: Help to understand numeric-character-numeric conversion?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132661#M36079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom and Mano,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks to both of you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mirisage&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Mar 2013 19:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-to-understand-numeric-character-numeric-conversion/m-p/132661#M36079</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2013-03-14T19:18:59Z</dc:date>
    </item>
  </channel>
</rss>

