<?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: conditional statement that convert specific variable from char to numeric. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506417#M135763</link>
    <description>Yes, as I said, it is the fast and dirty way to do it.</description>
    <pubDate>Mon, 22 Oct 2018 12:46:28 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2018-10-22T12:46:28Z</dc:date>
    <item>
      <title>conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506383#M135744</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to ask how can I create a conditional statement that convert specific variable from char to numeric.&lt;/P&gt;
&lt;P&gt;As you understand in some cases the variable will be numeric and then no need to transfer.&lt;/P&gt;
&lt;P&gt;And in other cases&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;variable will be char&amp;nbsp;and then need&amp;nbsp;to transfer it to numeric.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cases1:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Data a;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;input x $;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;case2:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cases1:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Data a;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;input x ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;3&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&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;</description>
      <pubDate>Mon, 22 Oct 2018 10:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506383#M135744</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-10-22T10:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506389#M135748</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data a;
input x ;
cards;
1
2
3
;
run;

data b;
length x $10.;
set a(rename=(x=_x));
x=put(_x,best.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Oct 2018 10:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506389#M135748</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-10-22T10:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506390#M135749</link>
      <description>&lt;P&gt;Am sure a basic question like this you asked before?&lt;/P&gt;
&lt;PRE&gt;data want;
  set a;
  if notdigit(x) then y=.;
  else y=input(x,best.);
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Oct 2018 10:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506390#M135749</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-22T10:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506396#M135752</link>
      <description>&lt;P&gt;The fast and dirty way to do it is this, no need for any conditional statements:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  length x 8; /* declare X as numeric */
  set a(rename=(x=_x));
  x=_x;
  drop _x;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If the original X is character, you will get a message about conversion in the log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 11:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506396#M135752</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-22T11:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506402#M135755</link>
      <description>&lt;P&gt;Not sure what level you consider "&lt;SPAN&gt;you will get a message about conversion in the log" - this would come out as an issue for my logs.&amp;nbsp; Implicit conversion should be avoid.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 12:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506402#M135755</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-22T12:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506417#M135763</link>
      <description>Yes, as I said, it is the fast and dirty way to do it.</description>
      <pubDate>Mon, 22 Oct 2018 12:46:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506417#M135763</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-22T12:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: conditional statement that convert specific variable from char to numeric.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506480#M135794</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to ask how can I create a conditional statement that convert specific variable from char to numeric.&lt;/P&gt;
&lt;P&gt;As you understand in some cases the variable will be numeric and then no need to transfer.&lt;/P&gt;
&lt;P&gt;And in other cases&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;variable will be char&amp;nbsp;and then need&amp;nbsp;to transfer it to numeric.&lt;/S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LOCKQUOTE&gt;
&lt;P&gt;Short answer: you can't. A variable type is set at creation, either numeri or character. If a value is going to hold non-missing character values the variable type&amp;nbsp;must be character. You can have two variables, on character one numeric and conditionally assign VALUES, but not types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are attempting to fix data that was imported in an undesired variable type, or inconsistent, then fix the import/ read step to use the correct type consistently. Your "example" is very common when relying on the guessing procedure Proc Import to read data and then combine data sets and discovering that because of the contents of the files Proc Import guessed differently for some files.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 15:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/conditional-statement-that-convert-specific-variable-from-char/m-p/506480#M135794</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-22T15:44:35Z</dc:date>
    </item>
  </channel>
</rss>

