SPSS Statistics

 View Only
  • 1.  Substring variable

    Posted Thu September 23, 2021 09:53 AM
    Good evening, 
    I was wondering if someone could help me out here. 
    I'm working with the national inpatient sample database which uses ICD 10 codes for diseases.

    I have the following variables: I10_DX1 through I10_DX40

    Each of these variables have ICD codes for example stroke: Every ICD code for stroke starts with "I63"

    I would like to create a new variable called "STROKE" using syntax to loop through 10_DX1 through I10_DX40 looking for "I63" and give a value of 1 if present and 0 if not present. I have been able to do this on STATA however STATA is too slow. I pasted the code I used in STATA as an example. 

    generate STROKE=0
    foreach var of varlist I10_DX2-I10_DX40 {
    replace STROKE=1 if substr(`var',1,4)=="I63"
    }

    Thanks 

    Christian

    ------------------------------
    Christian Torres
    ------------------------------

    #SPSSStatistics


  • 2.  RE: Substring variable

    Posted Thu September 23, 2021 10:19 AM
    You could try:

    compute stroke=0.
    do repeat I=I10_DX2 to I10_DX40.
    if char.substr(I,1,4) eq "I63" stroke=1.
    end repeat.
    execute.






  • 3.  RE: Substring variable

    IBM Champion
    Posted Thu September 23, 2021 11:42 AM
    I think you meant char.substr(I, 1, 3), since the third parameter is the length.

    --





  • 4.  RE: Substring variable

    Posted Thu September 23, 2021 11:45 AM
    True. I noticed that I forgot to change that in the original code only after I posted. Thanks.

    ------------------------------
    Rick Marcantonio
    Quality Assurance
    IBM
    ------------------------------