Hi,
I have a dataset of numeric diagnostic codes from the icd-9 system (string variable). These codes range from 290-319, some with decimals, for instance:
id icd9
1 290.1
2 311
3 311.12
4 312
5 312
6 319.9
7 319.44
I need to group this variable (icd9), and have been using this command:
gen icd9gr=.
replace icd9gr=1 if substr(icd9n,1,3)== "290"
replace icd9gr=1 if substr(icd9n,1,3)== "291"
replace icd9gr=1 if substr(icd9n,1,3)== "292"
and so on
However this did not detect any of the codes with decimals. I actually do not need the decimal-numbers, so I tried to first use this command:
replace icd9 = subinstr(icd9, ".", "",.)
Then repeated the gen-and replace-command above, however the output is still not correct (some of the codes are not included).
Then I tried the following: gen icd9n = substr(icd9,1,3), however some of the numbers then turns out with only to digits. For instance 300.40 (original value) -> 30040 (after "replace icd"-command above) -> 30 (after final command).
Hope this makes sense to someone.
Help is much appreciated.
I have a dataset of numeric diagnostic codes from the icd-9 system (string variable). These codes range from 290-319, some with decimals, for instance:
id icd9
1 290.1
2 311
3 311.12
4 312
5 312
6 319.9
7 319.44
I need to group this variable (icd9), and have been using this command:
gen icd9gr=.
replace icd9gr=1 if substr(icd9n,1,3)== "290"
replace icd9gr=1 if substr(icd9n,1,3)== "291"
replace icd9gr=1 if substr(icd9n,1,3)== "292"
and so on
However this did not detect any of the codes with decimals. I actually do not need the decimal-numbers, so I tried to first use this command:
replace icd9 = subinstr(icd9, ".", "",.)
Then repeated the gen-and replace-command above, however the output is still not correct (some of the codes are not included).
Then I tried the following: gen icd9n = substr(icd9,1,3), however some of the numbers then turns out with only to digits. For instance 300.40 (original value) -> 30040 (after "replace icd"-command above) -> 30 (after final command).
Hope this makes sense to someone.
Help is much appreciated.

Comment