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.
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.
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.
That fixed it. Thanks much.
P.S.
I actually removed the commas, thinking that would help for some reason. It didn't.
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.