BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SSG
Fluorite | Level 6 SSG
Fluorite | Level 6

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 😎 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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Technically, you should add commas within the IN operator:

if presn_ethnic+cd in (2, 3, 5, 😎 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

4 REPLIES 4
Astounding
PROC Star

Technically, you should add commas within the IN operator:

if presn_ethnic+cd in (2, 3, 5, 😎 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.

SSG
Fluorite | Level 6 SSG
Fluorite | Level 6

That fixed it.  Thanks much.

P.S.

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

data_null__
Jade | Level 19

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.

Astounding
PROC Star

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;


sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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