<?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 Character to numeric conversion doubt in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507260#M136130</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please explain the below mentioned code as to why the answer is C. As per my understanding the answer should be B because the automatic conversion will happen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;The following SAS program is submitted:&lt;/DIV&gt;&lt;DIV&gt;data work.retail;&lt;/DIV&gt;&lt;DIV&gt;cost = `20000';&lt;/DIV&gt;&lt;DIV&gt;total= .10* cost&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;What is the result?&lt;/DIV&gt;&lt;DIV&gt;A. The value of the variable TOTAL in the output data set is 2000. No messages are written to the SAS log.&lt;/DIV&gt;&lt;DIV&gt;B. The value of the variable TOTAL in the output data set is 2000. A note that conversion has taken place is&lt;/DIV&gt;&lt;DIV&gt;written to the SAS log.&lt;/DIV&gt;&lt;DIV&gt;C. The value of the variable TOTAL in the output data set is missing. An error message is written to the SAS&lt;/DIV&gt;&lt;DIV&gt;log.&lt;/DIV&gt;&lt;DIV&gt;D. The variable TOTAL in the output data set has no value. The program fails to execute due to a syntax error.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Although i did get answer C when i ran the code but i am just posting here to understand the logic.&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance.&lt;/DIV&gt;</description>
    <pubDate>Wed, 24 Oct 2018 17:58:35 GMT</pubDate>
    <dc:creator>ShwetaMalhotra</dc:creator>
    <dc:date>2018-10-24T17:58:35Z</dc:date>
    <item>
      <title>Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507260#M136130</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please explain the below mentioned code as to why the answer is C. As per my understanding the answer should be B because the automatic conversion will happen.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;The following SAS program is submitted:&lt;/DIV&gt;&lt;DIV&gt;data work.retail;&lt;/DIV&gt;&lt;DIV&gt;cost = `20000';&lt;/DIV&gt;&lt;DIV&gt;total= .10* cost&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;What is the result?&lt;/DIV&gt;&lt;DIV&gt;A. The value of the variable TOTAL in the output data set is 2000. No messages are written to the SAS log.&lt;/DIV&gt;&lt;DIV&gt;B. The value of the variable TOTAL in the output data set is 2000. A note that conversion has taken place is&lt;/DIV&gt;&lt;DIV&gt;written to the SAS log.&lt;/DIV&gt;&lt;DIV&gt;C. The value of the variable TOTAL in the output data set is missing. An error message is written to the SAS&lt;/DIV&gt;&lt;DIV&gt;log.&lt;/DIV&gt;&lt;DIV&gt;D. The variable TOTAL in the output data set has no value. The program fails to execute due to a syntax error.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Although i did get answer C when i ran the code but i am just posting here to understand the logic.&lt;/DIV&gt;&lt;DIV&gt;Thanks in advance.&lt;/DIV&gt;</description>
      <pubDate>Wed, 24 Oct 2018 17:58:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507260#M136130</guid>
      <dc:creator>ShwetaMalhotra</dc:creator>
      <dc:date>2018-10-24T17:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507262#M136132</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;Can anyone please explain the below mentioned code as to why the answer is C"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The answer is not C&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2604 data work.retail;&lt;BR /&gt;2605 cost = '20000';&lt;BR /&gt;2606 total= .10* cost;&lt;BR /&gt;2607 put total= ;&lt;BR /&gt;2608 run;&lt;/P&gt;
&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt; (Line) : (Column).&lt;BR /&gt; 2606:13&lt;BR /&gt;total=2000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAS will auto convert using BESTW informat/format if it can. If it cannot,it will generate missing values in most operation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;However, Let's take&amp;nbsp; a step further to make a note when you play with APP functions. The autoconvert behavior isn't quite the same.&amp;nbsp; Well APP is out of scope for this thread but good to be aware.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 18:05:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507262#M136132</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-24T18:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507263#M136133</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/240784"&gt;@ShwetaMalhotra&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please explain the below mentioned code as to why the answer is C. As per my understanding the answer should be B because the automatic conversion will happen.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;The following SAS program is submitted:&lt;/DIV&gt;
&lt;DIV&gt;data work.retail;&lt;/DIV&gt;
&lt;DIV&gt;cost = `20000';&lt;/DIV&gt;
&lt;DIV&gt;total= .10* cost&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;What is the result?&lt;/DIV&gt;
&lt;DIV&gt;A. The value of the variable TOTAL in the output data set is 2000. No messages are written to the SAS log.&lt;/DIV&gt;
&lt;DIV&gt;B. The value of the variable TOTAL in the output data set is 2000. A note that conversion has taken place is&lt;/DIV&gt;
&lt;DIV&gt;written to the SAS log.&lt;/DIV&gt;
&lt;DIV&gt;C. The value of the variable TOTAL in the output data set is missing. An error message is written to the SAS&lt;/DIV&gt;
&lt;DIV&gt;log.&lt;/DIV&gt;
&lt;DIV&gt;D. The variable TOTAL in the output data set has no value. The program fails to execute due to a syntax error.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Although i did get answer C when i ran the code but i am just posting here to understand the logic.&lt;/DIV&gt;
&lt;DIV&gt;Thanks in advance.&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The answer should be D because of the missing semicolon between cost and run.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 18:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507263#M136133</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-10-24T18:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507265#M136135</link>
      <description>&lt;P&gt;Sir that could be typo by OP lol&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I mean missing semicolon&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT Sorry you are right.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 18:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507265#M136135</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-24T18:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507282#M136139</link>
      <description>&lt;P&gt;Clearly, the program has been retyped and does not accurately reproduce the original question.&amp;nbsp; Besides the missing semicolon, this line is also incorrect:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;cost = `20000';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notice the strange open quote.&amp;nbsp; So the right answer depends on what belongs in the question.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 18:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507282#M136139</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-10-24T18:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507286#M136140</link>
      <description>&lt;P&gt;Hard to tell since your posted code is missing a semi-colon and has backwards tick in place of one of the single quotes around the string literal.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you fix those then it should find that one tenth of 20,000 is 2,000, so the answer is B.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.retail;
  cost = '20000';
  total= 0.10* cost ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the answer to be C the value of the character variable would need to be something that SAS could not convert automatically.&amp;nbsp; For example with a comma.&lt;/P&gt;
&lt;PRE&gt;134  data work.retail;
135    cost = '20000';
136    total= 0.10* cost ;
137    put (_all_) (=/);
138  run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      136:16

cost=20000
total=2000
NOTE: The data set WORK.RETAIL has 1 observations and 2 variables.


139
140  data work.retail;
141    cost = '20,000';
142    total= 0.10* cost ;
143    put (_all_) (=/);
144  run;

NOTE: Character values have been converted to numeric values at the places given by:
      (Line):(Column).
      142:16
NOTE: Invalid numeric data, cost='20,000' , at line 142 column 16.

cost=20,000
total=.
cost=20,000 total=. _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 142:14
NOTE: The data set WORK.RETAIL has 1 observations and 2 variables.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 19:00:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507286#M136140</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-24T19:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Character to numeric conversion doubt</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507301#M136144</link>
      <description>&lt;P&gt;Thanks a lot Tom for the answer as well as explaining the question and the errors.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Oct 2018 19:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-numeric-conversion-doubt/m-p/507301#M136144</guid>
      <dc:creator>ShwetaMalhotra</dc:creator>
      <dc:date>2018-10-24T19:50:36Z</dc:date>
    </item>
  </channel>
</rss>

