**************************************************************************************************** * PROGRAM OVERVIEW **************************************************************************************************** * * PROGRAM: ms_extractdrugs.sas * * Created (mm/dd/yyyy): 07/31/2014 * Last modified: 07/31/2014 * Version: 1.1 * *-------------------------------------------------------------------------------------------------- * PURPOSE: * This program pre extracts dispensing claims based on either 9 or 11 digit NDCs. * * Program inputs: * -dataset to extract records from * -dataset containing the list of codes to extract * * Program outputs: * -dataset containing the extracted records * * PARAMETERS: * -datafile = Name of the dataset to extract records from. * -datavar = Name of the variable containing the codes. * -lookfile = Name of the sas dataset containing the list of codes to extract. * -lookvar = Name of the variable containing the codes to extract. * -outfile = Name of the output dataset containing the extracted records. * * Programming Notes: * * * *-------------------------------------------------------------------------------------------------- * CONTACT INFO: * Mini-Sentinel Coordinating Center * info@mini-sentinel.org * *-------------------------------------------------------------------------------------------------- * CHANGE LOG: * * Version Date Initials Comment (reference external documentation when available) * ------- -------- -------- --------------------------------------------------------------- * mm/dd/yy * ***************************************************************************************************; %MACRO ms_extractdrugs(datafile=, datavar=, lookfile=, lookvar=, outfile=); %put =====> MACRO CALLED: ms_extractdrugs v1.1; %GLOBAL ISCode9; %GLOBAL ISCode11; %GLOBAL NoObs; %LET ISCode9=0; %LET ISCode11=0; %LET NoObs=; data _null_; set &lookfile.; if length(&lookvar.)=9 then call symput("ISCode9",put(1,best.)); if length(&lookvar.)=11 then call symput("ISCode11",put(1,best.)); run; %PUT &ISCode9; %PUT &ISCode11; data _null_; set &lookfile.; if &ISCode11.=0 then call symput("NoObs","(obs=0)"); run; /*Extract 9 and/or 11 digit Codes claims*/ %MACRO WRAPPER; %IF %EVAL(&ISCode9.>0) %THEN %DO; *Extract all claims using 9 digit RawCodes; proc sql noprint; create table &outfile.(drop=&lookvar.) as select claim.Patid, claim.Rxdate, claim.NDC, claim.RxSup, claim.RxAmt, CodeList.* from &lookfile. as CodeList, &datafile. as claim where RxSup > 0 and substr(claim.&datavar.,1,9) = CodeList.&lookvar.; quit; %END; /*%IF %EVAL(&ISCode11.>0) %THEN %DO;*/ *Extract all claims using 11 digit RawCodes; proc sql noprint; create table _predrugs(drop=&lookvar.) as select claim.Patid, claim.Rxdate, claim.NDC, claim.RxSup, claim.RxAmt, CodeList.* from &lookfile. as CodeList, &datafile.&NoObs. as claim where RxSup > 0 and claim.&datavar. = CodeList.&lookvar.; quit; *Setting claims extracted using 9 and 11 NDCs together; %IF %EVAL(&ISCode9.>0) %THEN %DO; *Delete the empty table created from the MSCDM dispensing to avoid w.a.r.n.i.n.g.s.; proc datasets library=work nolist; append base=&outfile. data=_predrugs FORCE; delete _predrugs; quit; %END; %ELSE %DO; proc datasets library=work nolist nowarn; delete &outfile.; change _predrugs = &outfile.; quit; %END; /*%END;*/ %MEND WRAPPER; %WRAPPER; %put NOTE: ********END OF MACRO: ms_extractdrugs v1.1********; %MEND ms_extractdrugs;