<?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: remove character from numeric column in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731239#M28424</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305675"&gt;@Pooja98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks a lot... i got the answer but i still have doubt in this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"var=ifc(input(var,??best.)=.,'',var);"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What it mean: input(var, ??best.)= .&lt;/P&gt;
&lt;P&gt;The input function converts character to numeric then what is that "=."........&lt;/P&gt;
&lt;P&gt;can you please explain that&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your variable is character this code is using the INPUT() function to check it the value can be converted into a number.&amp;nbsp; When it can it sets the the variable back to itself otherwise it sets it to blanks.&lt;/P&gt;
&lt;P&gt;The ?? before the informat will suppress any error messages about strings that cannot be converted into a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make it less confusing by just using an IF/THEN statement instead of the confusing IFC() function.&lt;/P&gt;
&lt;P&gt;You can make the test less confusing also by not trying to use the name of a FORMAT in the place where SAS is expecting the name of an INFORMAT.&amp;nbsp; If you reference BEST as an INFORMAT it is just an alias for the normal numeric informat.&lt;/P&gt;
&lt;P&gt;You can also use the MISSING() function instead of just comparing the INPUT() result to the numeric missing value.&amp;nbsp; In addition to being more readable for humans this will also catch the issue where value like E being converted to special missing .E which is not equal to . but will be considered missing by the MISSING() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(input(var,??32.)) then var=' ';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note also that if you wanted to create an actual numeric variable you will have to give that variable a new name.&amp;nbsp; You cannot change the type of an existing variable.&amp;nbsp; In that case the code is even easier (clearer).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if have an existing dataset named HAVE with a character variable named STR and you want to create a new variable name NUM that is numeric then use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  num = input(str,??32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you would like to see messages in the log when the value of STR could not be converted to a number then remove the ?? from before the informat.&lt;/P&gt;</description>
    <pubDate>Sun, 04 Apr 2021 15:07:25 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-04T15:07:25Z</dc:date>
    <item>
      <title>remove character from numeric column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/730928#M28410</link>
      <description>&lt;P&gt;&amp;nbsp;hi experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the dataset i have&lt;/P&gt;&lt;P&gt;column1&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;P&gt;2.5&lt;/P&gt;&lt;P&gt;30.59&lt;/P&gt;&lt;P&gt;H 200&lt;/P&gt;&lt;P&gt;87 mg/dL&lt;/P&gt;&lt;P&gt;90 L&lt;/P&gt;&lt;P&gt;28.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the dataset that i want&lt;/P&gt;&lt;P&gt;column1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.5&lt;/P&gt;&lt;P&gt;30.59&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;&lt;P&gt;28.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if my column contain any variable, i want to set that as missing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 09:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/730928#M28410</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2021-04-02T09:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: remove character from numeric column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/730930#M28411</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length var $20;
  infile datalines dlm=',';
  input var $;
datalines;
-
2.5
30.59
H 200
87 mg/dL
90 L
28.3
;
run;

data want;
  set have;
  var=ifc(input(var,??best.)=.,'',var);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Apr 2021 09:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/730930#M28411</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-04-02T09:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: remove character from numeric column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731237#M28423</link>
      <description>&lt;P&gt;Thanks a lot... i got the answer but i still have doubt in this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"var=ifc(input(var,??best.)=.,'',var);"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What it mean: input(var, ??best.)= .&lt;/P&gt;&lt;P&gt;The input function converts character to numeric then what is that "=."........&lt;/P&gt;&lt;P&gt;can you please explain that&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 14:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731237#M28423</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2021-04-04T14:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: remove character from numeric column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731239#M28424</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305675"&gt;@Pooja98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks a lot... i got the answer but i still have doubt in this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"var=ifc(input(var,??best.)=.,'',var);"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What it mean: input(var, ??best.)= .&lt;/P&gt;
&lt;P&gt;The input function converts character to numeric then what is that "=."........&lt;/P&gt;
&lt;P&gt;can you please explain that&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since your variable is character this code is using the INPUT() function to check it the value can be converted into a number.&amp;nbsp; When it can it sets the the variable back to itself otherwise it sets it to blanks.&lt;/P&gt;
&lt;P&gt;The ?? before the informat will suppress any error messages about strings that cannot be converted into a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make it less confusing by just using an IF/THEN statement instead of the confusing IFC() function.&lt;/P&gt;
&lt;P&gt;You can make the test less confusing also by not trying to use the name of a FORMAT in the place where SAS is expecting the name of an INFORMAT.&amp;nbsp; If you reference BEST as an INFORMAT it is just an alias for the normal numeric informat.&lt;/P&gt;
&lt;P&gt;You can also use the MISSING() function instead of just comparing the INPUT() result to the numeric missing value.&amp;nbsp; In addition to being more readable for humans this will also catch the issue where value like E being converted to special missing .E which is not equal to . but will be considered missing by the MISSING() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(input(var,??32.)) then var=' ';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note also that if you wanted to create an actual numeric variable you will have to give that variable a new name.&amp;nbsp; You cannot change the type of an existing variable.&amp;nbsp; In that case the code is even easier (clearer).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if have an existing dataset named HAVE with a character variable named STR and you want to create a new variable name NUM that is numeric then use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  num = input(str,??32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you would like to see messages in the log when the value of STR could not be converted to a number then remove the ?? from before the informat.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 15:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731239#M28424</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-04T15:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: remove character from numeric column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731294#M28426</link>
      <description>&lt;P&gt;Thank you for your explanation, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;I also noticed after posting that ifc would cause unnecessary processing, so I think a simple if then statement would be better.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 00:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/remove-character-from-numeric-column/m-p/731294#M28426</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-04-05T00:44:18Z</dc:date>
    </item>
  </channel>
</rss>

