<?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: Convert string variable to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37866#M7556</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Once again, it worked, and I thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One last thing. It turns out that there were a total of 5 variables that needed to be converted, and I just added them to the code as indicated above. All 5 variables were converted, and the old ones dropped, which is great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, one of the variables had two decimal places (it ranged from 1 to 5, so values could be 1.77 and so forth). The variable is AVG_ED08. I tried adding two zeroes after the period (see below) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AVG_ED08=input(oldAVG_ED08,1.00);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the two decimal places were dropped in the new file. Can you please tell me the code for retaining the two decimal places? Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 30 Oct 2011 06:03:05 GMT</pubDate>
    <dc:creator>kvc</dc:creator>
    <dc:date>2011-10-30T06:03:05Z</dc:date>
    <item>
      <title>Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37861#M7551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been trying to figure out how to convert a string variable to numeric in my dataset. The dataset was originally in SPSS, where I changed the variable API08 from string to numeric. However, after saving the dataset in SAS, the variable continues to be read as string when I try to conduct PROC REG. Here is the error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR: Variable API08 should be either numeric or in CLASSES list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This variable is an academic performance index ranging from 200 to 1000. The variable is already a number. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After searching on Google for some kind of code (couldn't find it in my SAS book), I found this code and example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CODE:&lt;/P&gt;&lt;P&gt;numericVar = input(charVar, informat.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EXAMPLE:&lt;/P&gt;&lt;P&gt;data = dataset;&lt;/P&gt;&lt;P&gt;charVar='1234';&lt;/P&gt;&lt;P&gt;numericvar=input(charvar,4.0);&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question - how do I take that code and write it for my variable? Thanks for considering my question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 00:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37861#M7551</guid>
      <dc:creator>kvc</dc:creator>
      <dc:date>2011-10-30T00:50:40Z</dc:date>
    </item>
    <item>
      <title>Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37862#M7552</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Almost exactly the way shown in your example.&amp;nbsp; Say your current SAS file was called "have" and that you didn't want to risk messing it up, thus wanted to create a new dataset called "want".&amp;nbsp; And, you ets say that you didn't want to change the name.&amp;nbsp; I'd accomplish it as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=old);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have (rename=(AP108=old));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; AP108=input(old,4.0);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 01:21:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37862#M7552</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-30T01:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37863#M7553</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It worked! Thank you so much! I've been struggling with this for days.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 03:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37863#M7553</guid>
      <dc:creator>kvc</dc:creator>
      <dc:date>2011-10-30T03:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37864#M7554</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a tag-on question. It looks like there is another string variable that also needs to be converted. Can I do it in the same step as API08? Or do I have to create another dataset for the second variable. The second variable is VALID08, which ranges from 98 to 1100. Thanks for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 04:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37864#M7554</guid>
      <dc:creator>kvc</dc:creator>
      <dc:date>2011-10-30T04:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37865#M7555</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;data want (drop=old:);&amp;nbsp; /*This now drops any variable that starts with the string old*/&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp; set have (rename=(API08=oldAPI VALID08=oldVALID));&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; API08=input(oldAPI,4.0);&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp; VALID08=input(oldVALID,4.0);&lt;/P&gt;&lt;P style="background-color: #ffffff; font-size: 12px; font-family: Arial, Helvetica, sans-serif;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 04:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37865#M7555</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-10-30T04:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37866#M7556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Once again, it worked, and I thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One last thing. It turns out that there were a total of 5 variables that needed to be converted, and I just added them to the code as indicated above. All 5 variables were converted, and the old ones dropped, which is great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, one of the variables had two decimal places (it ranged from 1 to 5, so values could be 1.77 and so forth). The variable is AVG_ED08. I tried adding two zeroes after the period (see below) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AVG_ED08=input(oldAVG_ED08,1.00);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the two decimal places were dropped in the new file. Can you please tell me the code for retaining the two decimal places? Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 06:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37866#M7556</guid>
      <dc:creator>kvc</dc:creator>
      <dc:date>2011-10-30T06:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37867#M7557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Change the format used to convert the character string to a number in the INPUT function call.&lt;/P&gt;&lt;P&gt;For formats and informats the number before the period is the total length and the number after the period is the number of decimal places.&amp;nbsp; But for informats if the text has a decimal in it then it will use it when reading the data and ignores the number of decimals when in the informat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Art's code uses 4.0 as the informat which will handle character strings up to 4 characters long.&lt;/P&gt;&lt;P&gt;Your code uses 1.0 which will handle only a single character.&lt;/P&gt;&lt;P&gt; I would recommend using 12. as the informat which is the normal length SAS uses for auto conversion between text and numbers. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read up about formats and informats in the manuals.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 Oct 2011 11:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37867#M7557</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-10-30T11:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert string variable to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37868#M7558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you, this worked. This time I waited until I ran the analyses completely before I responded in case anything else came up.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Oct 2011 04:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-string-variable-to-numeric/m-p/37868#M7558</guid>
      <dc:creator>kvc</dc:creator>
      <dc:date>2011-10-31T04:20:44Z</dc:date>
    </item>
  </channel>
</rss>

