Help using Base SAS procedures

Invalid numeric data error

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Invalid numeric data error

I don't understand why when I'm running this code

 

length ICD_cat 3. ICD_other $ 1  ICD_cat10 2. DIAGNOSIS_GROUP $ 50 /*PEPPER_DX_GROUP $ 50 */
            provst $ 2 benest $ 2 clm_yr 4. fiscal_yr 4. ICD_cat_num 3.;
        ICD_cat=substr(clm_prncpal_dgns_cd,1,3);
        ICD_cat_num=compress(ICD_cat,'','A');
        ICD_other=substr(clm_prncpal_dgns_cd,1,1);
        ICD_cat10=substr(clm_prncpal_dgns_cd,2,2);
        clm_yr=2015;
        if month(datepart(CLM_FROM_DT)) < 10 then fiscal_yr=2015;
        else fiscal_yr=(clm_yr + 1);


        /*Categorizing ICD-9 diagnosis codes (numeric) into diagnosis groups*/
        
        if clm_prncpal_dgns_cd in ('3310') then do; DIAGNOSIS_GROUP = 'Alzheimers'; end;
        else if fiscal_yr=2015 and ICD_other = 'V' then do; DIAGNOSIS_GROUP = 'Factors Influence Health'; end;
        else if fiscal_yr=2015 and ICD_other = 'E' then do; DIAGNOSIS_GROUP = 'External Causes'; end;
        else if fiscal_yr=2015 and 001<=ICD_cat_num<=139 then do; DIAGNOSIS_GROUP = 'Infection'; end;
        else if fiscal_yr=2015 and 140<=ICD_cat_num<=239 then do; DIAGNOSIS_GROUP = 'Cancer'; end;
        else if fiscal_yr=2015 and 240<=ICD_cat_num<=279 then do; DIAGNOSIS_GROUP = 'Endocrine'; end;
        else if fiscal_yr=2015 and 280<=ICD_cat_num<=289 then do; DIAGNOSIS_GROUP = 'Blood'; end;
        else if fiscal_yr=2015 and 290<=ICD_cat_num<=319 then do; DIAGNOSIS_GROUP = 'Mental'; end;
        else if fiscal_yr=2015 and 320<=ICD_cat_num<=389 then do; DIAGNOSIS_GROUP = 'Nervous System'; end;
        else if fiscal_yr=2015 and 390<=ICD_cat_num<=459 then do; DIAGNOSIS_GROUP = 'Circulatory'; end;
        else if fiscal_yr=2015 and 460<=ICD_cat_num<=519 then do; DIAGNOSIS_GROUP = 'Respiratory'; end;
        else if fiscal_yr=2015 and 520<=ICD_cat_num<=579 then do; DIAGNOSIS_GROUP = 'Digestive'; end;
        else if fiscal_yr=2015 and 580<=ICD_cat_num<=629 then do; DIAGNOSIS_GROUP = 'Genitourinary'; end;
        else if fiscal_yr=2015 and 630<=ICD_cat_num<=679 then do; DIAGNOSIS_GROUP = 'Childbirth/Pregnancy'; end;
        else if fiscal_yr=2015 and 680<=ICD_cat_num<=709 then do; DIAGNOSIS_GROUP = 'Skin'; end;
        else if fiscal_yr=2015 and 710<=ICD_cat_num<=739 then do; DIAGNOSIS_GROUP = 'Musculoskeletal'; end;
        else if fiscal_yr=2015 and 740<=ICD_cat_num<=759 then do; DIAGNOSIS_GROUP = 'Congenital Anomalies'; end;
        else if fiscal_yr=2015 and 760<=ICD_cat_num<=779 then do; DIAGNOSIS_GROUP = 'Prenatal'; end;
        else if fiscal_yr=2015 and 780<=ICD_cat_num<=799 then do; DIAGNOSIS_GROUP = 'Ill-Defined'; end;
        else if fiscal_yr=2015 and 800<=ICD_cat_num<=999 then do; DIAGNOSIS_GROUP = 'Injury/Poisoning'; end;

        /*Categorizing ICD-10 diagnosis codes (alphanumeric) into diagnosis groups. ICD-10 became effective October 1, 2015 (FY2016).  See http://www.icd10data.com/ICD10CM/Codes*/    
        
        else if fiscal_yr=2016 and (ICD_other='A' or ICD_other='B') then do; DIAGNOSIS_GROUP =  'Infection'; end;
        else if fiscal_yr=2016 and (ICD_other='C' or (ICD_other = 'D' and 00<=ICD_cat10<=49) or (ICD_other='D' and (substr(CLM_PRNCPAL_DGNS_CD,2,2))='3A')) then do; DIAGNOSIS_GROUP='Cancer'; end;
        else if fiscal_yr=2016 and (ICD_other='D' and 50<=ICD_cat10<=89) then do; DIAGNOSIS_GROUP = 'Blood'; end;
        else if fiscal_yr=2016 and (ICD_other='E' and (00<=ICD_cat10<=89)) then do; DIAGNOSIS_GROUP = 'Endocrine'; end;
        else if fiscal_yr=2016 and ICD_other='F' then do; DIAGNOSIS_GROUP = 'Mental'; end;
        else if fiscal_yr=2016 and ICD_other='G' then do; DIAGNOSIS_GROUP = 'Nervous System'; end;
        else if fiscal_yr=2016 and (ICD_other='H' and 00<=ICD_cat10<=59) then do; DIAGNOSIS_GROUP = 'Eye and Adnexa'; end;
        else if fiscal_yr=2016 and (ICD_other='H' and 60<=ICD_cat10<=95) then do; DIAGNOSIS_GROUP = 'Ear and Mastoid Process'; end;
        else if fiscal_yr=2016 and ICD_other='I' then do; DIAGNOSIS_GROUP = 'Circulatory'; end;
        else if fiscal_yr=2016 and ICD_other='J' then do; DIAGNOSIS_GROUP = 'Respiratory'; end;
        else if fiscal_yr=2016 and ICD_other='K' then do; DIAGNOSIS_GROUP = 'Digestive'; end;
        else if fiscal_yr=2016 and ICD_other='L' then do; DIAGNOSIS_GROUP = 'Skin'; end;
        else if fiscal_yr=2016 and ICD_other='M' then do; DIAGNOSIS_GROUP = 'Musculoskeletal'; end;
        else if fiscal_yr=2016 and ICD_other='N' then do; DIAGNOSIS_GROUP = 'Genitourinary'; end;
        else if fiscal_yr=2016 and ICD_other='O' then do; DIAGNOSIS_GROUP = 'Childbirth/Pregnancy'; end;
        else if fiscal_yr=2016 and ICD_other='P' then do; DIAGNOSIS_GROUP = 'Prenatal'; end;
        else if fiscal_yr=2016 and ICD_other='Q' then do; DIAGNOSIS_GROUP = 'Congenital Anomalies'; end;
        else if fiscal_yr=2016 and ICD_other='R' then DIAGNOSIS_GROUP = 'Ill-Defined';
        else if fiscal_yr=2016 and ICD_other in ('S','T') then do; DIAGNOSIS_GROUP = 'Injury/Poisoning'; end;
         else if fiscal_yr=2016 and (ICD_other='V' or ICD_other='Y') then do; DIAGNOSIS_GROUP = 'External Causes'; end;
        else if fiscal_yr=2016 and ICD_other='Z' then do; DIAGNOSIS_GROUP='Factors Influence Health'; end;
        else if ICD_cat = ' ' then do; DIAGNOSIS_GROUP = 'Missing'; end;

 

I get this note/error:

 

NOTE: Invalid numeric data, 'G20' , at line 81 column 17.
CLM_FROM_DT=13OCT2015:00:00:00  CLM_PRNCPAL_DGNS_CD=G20 CLM_PRNCPAL_DGNS_VRSN=0
ICD_cat=.  ICD_other=G  ICD_cat10=20  DIAGNOSIS_GROUP=Nervous System
clm_yr=2015 fiscal_yr=2016 ICD_cat_num=. _ERROR_=1 _N_=24

Any suggestions on how I can address this problem?  I tried "if/then" statements prior to these "if/then do" statements, but both approaches yield the same SAS note/error.  (I'm using SAS 9.4)

 

Thanks


Accepted Solutions
Solution
‎02-27-2017 12:37 PM
Super User
Posts: 6,928

Re: Invalid numeric data error

This

ICD_cat=substr(clm_prncpal_dgns_cd,1,3);

is the culprit.

By assigning a length of 3. (instead of $3.) to ICD_cat, you defined it numeric. As clm_prncpal_dgns_cd contains 'G20', SAS then fails when it tries to convert the result of the substr to numeric.

Make the length of ICD_cat in the length statement $3, and you should be fine.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 6,928

Re: Invalid numeric data error

[ Edited ]

Look at line 81 of your log. You're doing something there that assumes that the contents of CLM_PRNCPAL_DGNS_CD are numeric.

Probably an input() function or a mathematical operation.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,392

Re: Invalid numeric data error

Not read the whole things, but from your error (comments between ^):

 

length ICD_cat 3. ICD_other $ 1  ICD_cat10 2. DIAGNOSIS_GROUP $ 50 /*PEPPER_DX_GROUP $ 50 */
            provst $ 2 benest $ 2 clm_yr 4. fiscal_yr 4. ICD_cat_num 3.;

                                                                         ^ defined as num ^


        ICD_cat_num=compress(ICD_cat,'','A');

        ^ the above returns a string, icd_cat and the letter 'A', as that is not a number you get the error ^

Super User
Posts: 5,072

Re: Invalid numeric data error

It would be easier if you would tell us which line of the program corresponds to line 81 that the log is referencing.

 

At any rate, your LENGTH statement makes ID_CAT numeric.  That is probably wrong.  Change the LENGTH statement to make ID_CAT character and that should handle the problem.

Solution
‎02-27-2017 12:37 PM
Super User
Posts: 6,928

Re: Invalid numeric data error

This

ICD_cat=substr(clm_prncpal_dgns_cd,1,3);

is the culprit.

By assigning a length of 3. (instead of $3.) to ICD_cat, you defined it numeric. As clm_prncpal_dgns_cd contains 'G20', SAS then fails when it tries to convert the result of the substr to numeric.

Make the length of ICD_cat in the length statement $3, and you should be fine.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
New Contributor
Posts: 3

Re: Invalid numeric data error

Thank you! I think I'm getting closer to a fix. As advised, I defined ICD_cat as a character variable. I am now getting some error messages for another variable, ICD_cat10. See the error below.



NOTE: Invalid numeric data, ICD_cat10='3A' , at line 912 column 79.
CLM_PRNCPAL_DGNS_CD=D3A090I CD_cat=D3A ICD_other=D ICD_cat10=3A DIAGNOSIS_GROUP=Cancer provst=OH benest=OH

clm_yr=2015 fiscal_yr=2016 ICD_cat_num=3 _ERROR_=1 _N_=191179

Here's the corresponding log line:

912 else if fiscal_yr=2016 and (ICD_other='C' or (ICD_other = 'D' and 00<=ICD_cat10<=49) or (ICD_other='D' and

912! (substr(CLM_PRNCPAL_DGNS_CD,2,2))='3A')) then do; DIAGNOSIS_GROUP='Cancer'; end;


New Contributor
Posts: 3

Re: Invalid numeric data error

Issue solved.  Thank you all for your assistance.

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 204 views
  • 2 likes
  • 4 in conversation