<?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 do convert categorical value to numeric ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825038#M325864</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/225295"&gt;@ndamo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear Community ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to convert the value from categorical data to numeric no success. In my SAS data set (raw data), I have values like 20,25, and 15,10,0. I tried to use the format BEST12. and 8. , it still did not work and I got:&lt;BR /&gt;Old_Var New_Var (8.)&lt;BR /&gt;25 2&lt;BR /&gt;20 2&lt;BR /&gt;15 1&lt;/P&gt;
&lt;P&gt;Any help welcome&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A FORMAT is not going to be much help.&amp;nbsp; FORMATs convert value to text.&lt;/P&gt;
&lt;P&gt;Perhaps you meant you tried an INFORMAT?&amp;nbsp; INFORMATS convert text to values.&amp;nbsp; But BEST is not an INFORMAT (if you do use it as an informat SAS will just assume you meant to use the normal numeric informat).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have not really explained what you are trying to do.&amp;nbsp; If you want to convert a CHARACTER value to numeric then use the INPUT() function with a numeric informat.&amp;nbsp; I suspect that your original variable had leading spaces (or was already numeric forcing SAS to first convert it to a character string that the INPUT() function needs) and did not use a large enough width on the informat specification you used.&amp;nbsp; Note that the INPUT() function does not mind if you use a width on the informat that is large then the length of the string being read.&amp;nbsp; The maximum width you can use with the numeric informat is 32.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  number = input(string,32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you character variable is longer than 32 bytes then only the first 32 are read.&amp;nbsp; You might want to use the LEFT() function to remove any leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  number = input(left(string),32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Jul 2022 23:03:45 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-22T23:03:45Z</dc:date>
    <item>
      <title>How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/824619#M325667</link>
      <description>&lt;P&gt;Dear Community ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried to convert the value from categorical data to numeric no success. In my SAS data set (raw data), I have values like 20,25, and 15,10,0. I tried to use the format BEST12. and 8. , it still did not work and I got:&lt;BR /&gt;Old_Var New_Var (8.)&lt;BR /&gt;25 2&lt;BR /&gt;20 2&lt;BR /&gt;15 1&lt;/P&gt;&lt;P&gt;Any help welcome&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 12:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/824619#M325667</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-07-21T12:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825036#M325862</link>
      <description>I doubt if this type of data is Categorical, this seems like its a numerical data, kindly provide more info. say a screenshot of what you have.</description>
      <pubDate>Fri, 22 Jul 2022 22:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825036#M325862</guid>
      <dc:creator>himself</dc:creator>
      <dc:date>2022-07-22T22:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825038#M325864</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/225295"&gt;@ndamo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear Community ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried to convert the value from categorical data to numeric no success. In my SAS data set (raw data), I have values like 20,25, and 15,10,0. I tried to use the format BEST12. and 8. , it still did not work and I got:&lt;BR /&gt;Old_Var New_Var (8.)&lt;BR /&gt;25 2&lt;BR /&gt;20 2&lt;BR /&gt;15 1&lt;/P&gt;
&lt;P&gt;Any help welcome&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A FORMAT is not going to be much help.&amp;nbsp; FORMATs convert value to text.&lt;/P&gt;
&lt;P&gt;Perhaps you meant you tried an INFORMAT?&amp;nbsp; INFORMATS convert text to values.&amp;nbsp; But BEST is not an INFORMAT (if you do use it as an informat SAS will just assume you meant to use the normal numeric informat).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have not really explained what you are trying to do.&amp;nbsp; If you want to convert a CHARACTER value to numeric then use the INPUT() function with a numeric informat.&amp;nbsp; I suspect that your original variable had leading spaces (or was already numeric forcing SAS to first convert it to a character string that the INPUT() function needs) and did not use a large enough width on the informat specification you used.&amp;nbsp; Note that the INPUT() function does not mind if you use a width on the informat that is large then the length of the string being read.&amp;nbsp; The maximum width you can use with the numeric informat is 32.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  number = input(string,32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you character variable is longer than 32 bytes then only the first 32 are read.&amp;nbsp; You might want to use the LEFT() function to remove any leading spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  number = input(left(string),32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jul 2022 23:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825038#M325864</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-22T23:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825184#M325929</link>
      <description>Yes it's is . The original format is&lt;BR /&gt;1="25"&lt;BR /&gt;2="20"&lt;BR /&gt;3="15"&lt;BR /&gt;4="10"&lt;BR /&gt;5="5"&lt;BR /&gt;6="0"&lt;BR /&gt;I have just found an alternative to recode it if old var1=1 then new var =25......</description>
      <pubDate>Mon, 25 Jul 2022 08:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825184#M325929</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-07-25T08:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825185#M325930</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Tom ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have tried this but it did not work. The format in raw data is&amp;nbsp;1="25"&lt;BR /&gt;2="20"&lt;BR /&gt;3="15"&lt;BR /&gt;4="10"&lt;BR /&gt;5="5"&lt;BR /&gt;6="0"&lt;BR /&gt;I have just found an alternative to recode it if old var1=1 then new var =25......&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jul 2022 08:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825185#M325930</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-07-25T08:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825229#M325952</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/225295"&gt;@ndamo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi Tom ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I have tried this but it did not work. The format in raw data is&amp;nbsp;1="25"&lt;BR /&gt;2="20"&lt;BR /&gt;3="15"&lt;BR /&gt;4="10"&lt;BR /&gt;5="5"&lt;BR /&gt;6="0"&lt;BR /&gt;I have just found an alternative to recode it if old var1=1 then new var =25......&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you started with a number.&amp;nbsp; And you want to convert the formatted values back into a number.&amp;nbsp; Since formats generate text you will need an INPUT() function to convert the generated text back into a number.&amp;nbsp; If you don't know the name of the format the variable is using, but the format is already attached to the variable you can use the VVALUE() function to get the formatted value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  new=input(left(vvalue(old)),32.)
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Jul 2022 13:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825229#M325952</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-25T13:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do convert categorical value to numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825233#M325955</link>
      <description>Yes ,Thank you for such wonderful help!</description>
      <pubDate>Mon, 25 Jul 2022 13:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-convert-categorical-value-to-numeric/m-p/825233#M325955</guid>
      <dc:creator>ndamo</dc:creator>
      <dc:date>2022-07-25T13:22:31Z</dc:date>
    </item>
  </channel>
</rss>

