Help using Base SAS procedures

A different "Invalid Numeric Data" issue

Accepted Solution Solved
Reply
Occasional Contributor SSG
Occasional Contributor
Posts: 12
Accepted Solution

A different "Invalid Numeric Data" issue

The following code is part of a larger data step.  I am trying to create the field undr_flg:

undr_flg=0;

if PRSN_ETHNIC_CD in (2 3 5 8) then undr_flg=1;

if PRSN_ETHNIC_CD=6 then undr_flg=.;

I get the following error message when running this.

NOTE: Invalid numeric data, 'Underrepresented Minority flag' , at line 102 column 10

Every value for undr_flg then gets converted to missing.  PRSN_ETHNIC_CD is a numeric field, so that isn't the issue.  Any help would be appreciated.


Accepted Solutions
Solution
‎11-20-2013 11:59 AM
Super User
Posts: 5,077

Re: A different "Invalid Numeric Data" issue

Technically, you should add commas within the IN operator:

if presn_ethnic+cd in (2, 3, 5, 8) then undr_flg=1;

But that's not generating the message about invalid data.  A later statement is causing that, probably a LABEL statement with an extra semicolon.  For example, this would do it:

label abc='My label for the variable ABC';

         undr_flg='Underrepresented Minority flag';

When the LABEL statement labels multiple variables, it should be one long statement with just a single semicolon at the end.  In the example above, the semicolon at the end of the first line should be removed.  Leaving it in causes the message about invalid numeric data ... the last line is no longer part of the LABEL statement but is attempting to assign the value "Underrepresented Minority flag" to an existing variable.

Good luck.

View solution in original post


All Replies
Solution
‎11-20-2013 11:59 AM
Super User
Posts: 5,077

Re: A different "Invalid Numeric Data" issue

Technically, you should add commas within the IN operator:

if presn_ethnic+cd in (2, 3, 5, 8) then undr_flg=1;

But that's not generating the message about invalid data.  A later statement is causing that, probably a LABEL statement with an extra semicolon.  For example, this would do it:

label abc='My label for the variable ABC';

         undr_flg='Underrepresented Minority flag';

When the LABEL statement labels multiple variables, it should be one long statement with just a single semicolon at the end.  In the example above, the semicolon at the end of the first line should be removed.  Leaving it in causes the message about invalid numeric data ... the last line is no longer part of the LABEL statement but is attempting to assign the value "Underrepresented Minority flag" to an existing variable.

Good luck.

Occasional Contributor SSG
Occasional Contributor
Posts: 12

Re: A different "Invalid Numeric Data" issue

That fixed it.  Thanks much.

P.S.

I actually removed the commas, thinking that would help for some reason.  It didn't.

Respected Advisor
Posts: 3,777

Re: A different "Invalid Numeric Data" issue

Astounding wrote:

Technically, you should add commas within the IN operator:

if presn_ethnic+cd in (2, 3, 5, 8) then undr_flg=1;

I disagree SAS is a mostly blank delimited language and there is no reason to use commas where thay are not required.

Super User
Posts: 5,077

Re: A different "Invalid Numeric Data" issue

OK, I'll agree that it's a matter of style ... but it does give me some ideas for a neat little problem.  Something along the lines of:

if var in (1,235 6,789 10,246) then do;


☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 217 views
  • 0 likes
  • 3 in conversation