<?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: Basic Formatting Question - Invalid Numeric Data error with IF statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11893#M1520</link>
    <description>I was just using abbreviated code for example's sake, but here is the actual code and actual error message:&lt;BR /&gt;
&lt;BR /&gt;
data error_4;&lt;BR /&gt;
set error_3;&lt;BR /&gt;
&lt;BR /&gt;
*DEFINE PRA ERRORS;&lt;BR /&gt;
&lt;BR /&gt;
if ELIGIBILITY_2 or &lt;BR /&gt;
   ELIGIBILITY_3 or &lt;BR /&gt;
   ELIGIBILITY_4 or &lt;BR /&gt;
   ELIGIBILITY_5 or &lt;BR /&gt;
   ELIGIBILITY_6 or &lt;BR /&gt;
   ELIGIBILITY_7 or &lt;BR /&gt;
   ELIGIBILITY_8 or &lt;BR /&gt;
   ELIGIBILITY_9 in &lt;BR /&gt;
   ('64' '65' '66' '67' '68' '69' '70' 'h' 'i' 'k' 'l') then PRA_ERROR = 'Y';&lt;BR /&gt;
else PRA_ERROR = 'N';&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;
      (Line):(Column).&lt;BR /&gt;
      1248:4   1249:4   1250:4   1251:4   1252:4   1253:4   1254:4&lt;BR /&gt;
NOTE: Invalid numeric data, ELIGIBILITY_2='j' , at line 1248 column 4

Message was edited by: JonathanWarrick</description>
    <pubDate>Wed, 16 Feb 2011 19:57:49 GMT</pubDate>
    <dc:creator>JonathanWarrick</dc:creator>
    <dc:date>2011-02-16T19:57:49Z</dc:date>
    <item>
      <title>Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11891#M1518</link>
      <description>As a relative novice with SAS, formatting issues are still getting in the way of my coding.  I'm currently trying to create a column that generates a "Y" flag if another field has one of several values in it.  The code is:&lt;BR /&gt;
&lt;BR /&gt;
If ELIGIBILITY_2 or ELIGIBILITY_3 or ELIGIBILITY_4 in ('65' '66' 'a' 'b' 'c') then ERR = "Y";&lt;BR /&gt;
else ERR = "N";&lt;BR /&gt;
&lt;BR /&gt;
The variables the IF statement checks (ELG_2,3,4) are already char. variables, but when the code runs, for anything with a character value (a, b, c), the error comes back:&lt;BR /&gt;
&lt;BR /&gt;
"invalid numeric data ELG_2 = 'a' at line xyz"&lt;BR /&gt;
&lt;BR /&gt;
Two questions:&lt;BR /&gt;
&lt;BR /&gt;
First, why when I use this if statement does it automatically convert character values to numeric values.  And second, what do I need to do to fix this?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance!</description>
      <pubDate>Wed, 16 Feb 2011 19:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11891#M1518</guid>
      <dc:creator>JonathanWarrick</dc:creator>
      <dc:date>2011-02-16T19:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11892#M1519</link>
      <description>Your post content (the IF statement) and the SAS-generated diagnostic message are inconsistent (different SAS variable names used).&lt;BR /&gt;
&lt;BR /&gt;
Suggest that you will get the most effective feedback by posting a reply with the exact SAS log (COPY/PASTE) with your code revealed in total and also the SAS NOTE, WARNING and ERROR messages, as they are generated.&lt;BR /&gt;
&lt;BR /&gt;
Anything less creates a guessing-game, however I would tend to believe what SAS diagnostic information is being generated, to start - so, have a look at the SAS log, your code, and the specific SAS variables, by name -- remembering a SAS variable type defaults to NUMERIC, not CHARACTER, just in case there might be a misspelling.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Feb 2011 19:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11892#M1519</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-02-16T19:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11893#M1520</link>
      <description>I was just using abbreviated code for example's sake, but here is the actual code and actual error message:&lt;BR /&gt;
&lt;BR /&gt;
data error_4;&lt;BR /&gt;
set error_3;&lt;BR /&gt;
&lt;BR /&gt;
*DEFINE PRA ERRORS;&lt;BR /&gt;
&lt;BR /&gt;
if ELIGIBILITY_2 or &lt;BR /&gt;
   ELIGIBILITY_3 or &lt;BR /&gt;
   ELIGIBILITY_4 or &lt;BR /&gt;
   ELIGIBILITY_5 or &lt;BR /&gt;
   ELIGIBILITY_6 or &lt;BR /&gt;
   ELIGIBILITY_7 or &lt;BR /&gt;
   ELIGIBILITY_8 or &lt;BR /&gt;
   ELIGIBILITY_9 in &lt;BR /&gt;
   ('64' '65' '66' '67' '68' '69' '70' 'h' 'i' 'k' 'l') then PRA_ERROR = 'Y';&lt;BR /&gt;
else PRA_ERROR = 'N';&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;
      (Line):(Column).&lt;BR /&gt;
      1248:4   1249:4   1250:4   1251:4   1252:4   1253:4   1254:4&lt;BR /&gt;
NOTE: Invalid numeric data, ELIGIBILITY_2='j' , at line 1248 column 4

Message was edited by: JonathanWarrick</description>
      <pubDate>Wed, 16 Feb 2011 19:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11893#M1520</guid>
      <dc:creator>JonathanWarrick</dc:creator>
      <dc:date>2011-02-16T19:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11894#M1521</link>
      <description>Jonathan,&lt;BR /&gt;
&lt;BR /&gt;
I think you need to do something of the following:&lt;BR /&gt;
&lt;BR /&gt;
array elig ELIGIBILITY_: ;&lt;BR /&gt;
PRA_ERROR='N' ;&lt;BR /&gt;
 do over elig ;&lt;BR /&gt;
     if elig in (''64' '65' '66' '67' '68' '69' '70' 'h' 'i' 'k' 'l') then PRA_ERROR='Y' ;&lt;BR /&gt;
 end ;&lt;BR /&gt;
&lt;BR /&gt;
So this code sets everyone to N unless the value in the ELIG variables is in that string.  Is this what you were trying to do?&lt;BR /&gt;
&lt;BR /&gt;
Sue</description>
      <pubDate>Wed, 16 Feb 2011 20:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11894#M1521</guid>
      <dc:creator>SusieQ324</dc:creator>
      <dc:date>2011-02-16T20:04:59Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11895#M1522</link>
      <description>Your syntax is incorrect.&lt;BR /&gt;
&lt;BR /&gt;
[pre]ELIGIBILITY_2 or ELIGIBILITY_3[/pre]&lt;BR /&gt;
is an logical expression testing that either of the variables joined by the operator OR are 1(true).  But since they are character variables that don't store numbers you get invalid data message.&lt;BR /&gt;
&lt;BR /&gt;
you will need to test each eligibility as in this statement&lt;BR /&gt;
[pre]ELIGIBILITY_9 in   ('64' '65' '66' '67' '68' '69' '70' 'h' 'i' 'k' 'l')[/pre]&lt;BR /&gt;
&lt;BR /&gt;
You can use an array and a do loop to make the code less onerous.</description>
      <pubDate>Wed, 16 Feb 2011 20:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11895#M1522</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-16T20:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11896#M1523</link>
      <description>Your IF / THEN statement is coded incorrectly.  You are using an incorrectly formatted OR condition for each of your variable tests.  &lt;BR /&gt;
&lt;BR /&gt;
As mentioned SAS variable type defaults to NUMERIC, so if you notice the NOTE: you see where SAS converting character to numeric, as well.&lt;BR /&gt;
&lt;BR /&gt;
So, variables ELIGIBILITY_2 through ELIGIBILITY_8 are all being treated as NUMERIC tests (either ON or OFF, as in 1 or 0).&lt;BR /&gt;
&lt;BR /&gt;
If you want to test each of these variables against the IN operator list, they must be tested individually against the literal string.&lt;BR /&gt;
&lt;BR /&gt;
And, the presumption here is that your SAS variables listed in the IF / THEN are contained in the SAS member WORK.error_3 - given the NOTE where "j" is referenced, I would say that is the case.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Feb 2011 20:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11896#M1523</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-02-16T20:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11897#M1524</link>
      <description>Yes, that's exactly what I'm trying to do.  I'll try using an array to see if I can get the results I want with that.</description>
      <pubDate>Wed, 16 Feb 2011 20:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11897#M1524</guid>
      <dc:creator>JonathanWarrick</dc:creator>
      <dc:date>2011-02-16T20:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11898#M1525</link>
      <description>I've changed the code now to use an array:&lt;BR /&gt;
&lt;BR /&gt;
data error_4;&lt;BR /&gt;
PRA_ERROR_FLAG = "N";&lt;BR /&gt;
array pra_error 8 &lt;BR /&gt;
&lt;BR /&gt;
   ELIGIBILITY_2 &lt;BR /&gt;
   ELIGIBILITY_3 &lt;BR /&gt;
   ELIGIBILITY_4 &lt;BR /&gt;
   ELIGIBILITY_5  &lt;BR /&gt;
   ELIGIBILITY_6 &lt;BR /&gt;
   ELIGIBILITY_7 &lt;BR /&gt;
   ELIGIBILITY_8&lt;BR /&gt;
   ELIGIBILITY_9;&lt;BR /&gt;
&lt;BR /&gt;
do over pra_error;&lt;BR /&gt;
if pra_error in ('64' '65' '66' '67' '68' '69' '70' 'h' 'i' 'k' 'l') then PRA_ERROR_FLAG = 'Y'; &lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
set error_3;&lt;BR /&gt;
&lt;BR /&gt;
Now the errors the log is producing are related to formatting:&lt;BR /&gt;
&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_2 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_3 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_4 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_5 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_6 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_7 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_8 has been defined as both character and numeric.&lt;BR /&gt;
ERROR: Variable ELIGIBILITY_9 has been defined as both character and numeric.&lt;BR /&gt;
1551  run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions?&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 16 Feb 2011 20:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11898#M1525</guid>
      <dc:creator>JonathanWarrick</dc:creator>
      <dc:date>2011-02-16T20:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11899#M1526</link>
      <description>Check your ARRAY statement syntax.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Feb 2011 20:33:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11899#M1526</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2011-02-16T20:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11900#M1527</link>
      <description>and I think you need commas between each of your selected values in the ().</description>
      <pubDate>Wed, 16 Feb 2011 21:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11900#M1527</guid>
      <dc:creator>SusieQ324</dc:creator>
      <dc:date>2011-02-16T21:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11901#M1528</link>
      <description>Also, don't you need your SET statement before your ARRAY?</description>
      <pubDate>Wed, 16 Feb 2011 21:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11901#M1528</guid>
      <dc:creator>SusieQ324</dc:creator>
      <dc:date>2011-02-16T21:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11902#M1529</link>
      <description>JonathanWarrick &lt;BR /&gt;
 &lt;BR /&gt;
SusieQ has the answer to your problem! (it is not the commas)&lt;BR /&gt;
 &lt;BR /&gt;
I'm surprised you wanted to make the test before loading the data in the SET statement!&lt;BR /&gt;
  &lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 17 Feb 2011 17:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11902#M1529</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-17T17:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Basic Formatting Question - Invalid Numeric Data error with IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11903#M1530</link>
      <description>Sbb is right.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt;array pra_error 8 &lt;BR /&gt;
&lt;BR /&gt;
you definite a numeric array.But 'in' statement is character.&lt;BR /&gt;
Definite a char array&lt;BR /&gt;
array pra_error{*} $ 8  ................;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 18 Feb 2011 07:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Basic-Formatting-Question-Invalid-Numeric-Data-error-with-IF/m-p/11903#M1530</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-18T07:01:43Z</dc:date>
    </item>
  </channel>
</rss>

