Created
May 5, 2021 21:37
-
-
Save cjdinger/f56601b5a099d39011285d6cd8609b80 to your computer and use it in GitHub Desktop.
Using the RxNORM API via PROC HTTP
This file contains 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
/* this is viagra, from the example on https://mor.nlm.nih.gov/download/rxnav/RxNormAPIs.html# */ | |
%let rxcui = 213269; | |
/* | |
Or try acetaminophen with this code | |
%let rxcui = 209468; | |
*/ | |
/* allocate a file for the response */ | |
filename rx temp; | |
proc http | |
method='GET' | |
url="https://rxnav.nlm.nih.gov/REST/rxcui/&rxcui/ndcs.json" | |
out=rx; | |
run; | |
/* Check log for JSON content */ | |
data _null_; | |
rc = jsonpp('rx','log'); | |
run; | |
/* read into a data set */ | |
libname ndc JSON fileref=rx; | |
/* use PROC DATASETS lib=NDC; QUIT; if you want to explore */ | |
/* This one is wide because of the JSON structure */ | |
data ndcs_wide; | |
set ndc.ndclist_ndc; | |
run; | |
/* but this transforms into long, one row per NDC */ | |
data ndcs; | |
set ndc.ndclist_ndc; | |
keep ndc; | |
array c[*] $ ndc:; | |
do i = 1 to dim(c); | |
ndc = c[i]; | |
output; | |
end; | |
run; | |
/* Now loop through and get the NDC status for each */ | |
/* Okay...maybe these are always pretty much the same */ | |
/* but what do I know? */ | |
%macro getStatus(ndc=); | |
filename resp temp; | |
proc http | |
method='GET' | |
url="https://rxnav.nlm.nih.gov/REST/ndcstatus.json?ndc=&ndc." | |
out=resp; | |
run; | |
libname status JSON fileref=resp; | |
data s_&ndc.; | |
set status.ndcstatus; | |
drop ordinal:; | |
run; | |
%mend; | |
data _null_; | |
set ndcs; | |
call execute('%nrstr(%getStatus(ndc='||ndc||'))'); | |
run; | |
data allndcs; | |
set s_:; | |
run; | |
proc datasets nodetails nolist lib=work; | |
delete s_:; | |
quit; | |
title "NDC mappings for RXCUI=&rxcui."; | |
proc print data=allndcs; | |
run; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment