<?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 to convert a character to numeric when character is not a specific recognised form in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731821#M28450</link>
    <description>&lt;P&gt;Hi Please help, thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to covert one of my columns that contains a &lt;STRONG&gt;character&lt;/STRONG&gt; type in the form of the following --&amp;gt; e2/e2, e2/e3, e2/e4, e3/e3, e3/e4, and e4/e4 &lt;EM&gt;( $5. format)&lt;/EM&gt;. I plan to convert this to the &lt;STRONG&gt;numeric variable&lt;/STRONG&gt; before analysis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;such that&amp;nbsp;&lt;/P&gt;&lt;P&gt;e2/e2 , e2/e3 and&amp;nbsp; e3/e3&amp;nbsp; will be coded as 1&lt;/P&gt;&lt;P&gt;e2/e4, e3/e4 and e4/e4 will be coded as 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how to do this!&lt;/P&gt;&lt;P&gt;Please help. thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 07 Apr 2021 07:08:40 GMT</pubDate>
    <dc:creator>Gopi2</dc:creator>
    <dc:date>2021-04-07T07:08:40Z</dc:date>
    <item>
      <title>to convert a character to numeric when character is not a specific recognised form</title>
      <link>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731821#M28450</link>
      <description>&lt;P&gt;Hi Please help, thanks in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to covert one of my columns that contains a &lt;STRONG&gt;character&lt;/STRONG&gt; type in the form of the following --&amp;gt; e2/e2, e2/e3, e2/e4, e3/e3, e3/e4, and e4/e4 &lt;EM&gt;( $5. format)&lt;/EM&gt;. I plan to convert this to the &lt;STRONG&gt;numeric variable&lt;/STRONG&gt; before analysis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;such that&amp;nbsp;&lt;/P&gt;&lt;P&gt;e2/e2 , e2/e3 and&amp;nbsp; e3/e3&amp;nbsp; will be coded as 1&lt;/P&gt;&lt;P&gt;e2/e4, e3/e4 and e4/e4 will be coded as 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how to do this!&lt;/P&gt;&lt;P&gt;Please help. thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 07:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731821#M28450</guid>
      <dc:creator>Gopi2</dc:creator>
      <dc:date>2021-04-07T07:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: to convert a character to numeric when character is not a specific recognised form</title>
      <link>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731824#M28451</link>
      <description>&lt;P&gt;Create an informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input charvar $;
datalines;
e2/e2
e2/e3
e3/e3
e2/e4
e3/e4
e4/e4
;

proc format;
invalue convert
  "e2/e2" = 1
  "e2/e3" = 1
  "e3/e3" = 1
  "e2/e4" = 2
  "e3/e4" = 2
  "e4/e4" = 2
;
run;

data want;
set have;
numvar = input(charvar,convert.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 07:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731824#M28451</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-07T07:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: to convert a character to numeric when character is not a specific recognised form</title>
      <link>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731825#M28452</link>
      <description>thanks a lot for your quick response!</description>
      <pubDate>Wed, 07 Apr 2021 07:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731825#M28452</guid>
      <dc:creator>Gopi2</dc:creator>
      <dc:date>2021-04-07T07:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: to convert a character to numeric when character is not a specific recognised form</title>
      <link>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731827#M28453</link>
      <description>&lt;P&gt;You can also use a simple IF/THEN:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if charvar in ("e2/e2","e2/e3","e3/e3")
then numvar = 1;
else if charvar in ("e2/e4","e3/e4","e4/e4")
then numvar = 2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or a data step SELECT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
select (charvar);
  when ("e2/e2","e2/e3","e3/e3") numvar = 1;
  when ("e2/e4","e3/e4","e4/e4") numvar = 2;
  otherwise;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Apr 2021 07:40:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/731827#M28453</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-07T07:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: to convert a character to numeric when character is not a specific recognised form</title>
      <link>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/732115#M28472</link>
      <description>&lt;P&gt;thanks everything worked.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 23:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/to-convert-a-character-to-numeric-when-character-is-not-a/m-p/732115#M28472</guid>
      <dc:creator>Gopi2</dc:creator>
      <dc:date>2021-04-07T23:37:29Z</dc:date>
    </item>
  </channel>
</rss>

