Last active
August 29, 2015 14:08
-
-
Save benjamin-chan/446e6583396dc84f2775 to your computer and use it in GitHub Desktop.
ICD-9 code lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read ICD-9 diagnosis and procedure code descriptions | |
descLength <- "LONG" # Change "SHORT" to "LONG" for more detailed description | |
# Use Version 32 from cms.gov | |
# Version 32 Full and Abbreviated Code Titles – Effective October 1, 2014 | |
# Update if necessary | |
url <- "http://www.cms.gov/Medicare/Coding/ICD9ProviderDiagnosticCodes/Downloads/ICD-9-CM-v32-master-descriptions.zip" | |
# # # # # DO NOT CHANGE THE LINES BELOW # # # # # | |
setwd(tempdir()) | |
f1 <- tempfile() | |
download.file(url, f1) | |
filenames <- unzip(f1, list=TRUE) | |
if (descLength == "LONG") {len <- 255} else {len <- 25} | |
f2 <- grep(paste0(descLength, ".((DX)|(SG))\\.txt"), filenames$Name, value=TRUE) | |
f2 | |
unzip(f1, files=f2) | |
icd9DX <- read.fwf(grep("DX", f2, value=TRUE), | |
widths=c(6, len), | |
header=FALSE, | |
col.names=c("code", "desc"), | |
colClasses=rep("character", 2), | |
strip.white=TRUE, | |
stringsAsFactors=FALSE) | |
icd9SG <- read.fwf(grep("SG", f2, value=TRUE), | |
widths=c(5, len), | |
header=FALSE, | |
col.names=c("code", "desc"), | |
colClasses=rep("character", 2), | |
strip.white=TRUE, | |
stringsAsFactors=FALSE) | |
require(data.table) | |
icd9DX <- data.table(icd9DX) | |
icd9SG <- data.table(icd9SG) | |
str(icd9DX) | |
str(icd9SG) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment