****************************************************************************************************
* PROGRAM OVERVIEW
****************************************************************************************************
*
* PROGRAM: codedistribution_createdata.sas
* Created (mm/dd/yyyy): 04/16/2021
*
*--------------------------------------------------------------------------------------------------
* PURPOSE: The macro creates aggregated code distribution dataset and process code descriptions
*
* Program inputs:
*
* Program outputs:
*
* PARAMETERS:
*
* Programming Notes:
*
*
*--------------------------------------------------------------------------------------------------
* CONTACT INFO:
* Sentinel Coordinating Center
* info@sentinelsystem.org
*
***************************************************************************************************;
%macro codedistribution_createdata;
proc sql noprint;
select count(*) into :numgroupscodedist trimmed
from GroupsDist;
quit;
%do loopcount = 1 %to &numgroupscodedist.;
/* set parameters for this loop */
%let codedistexp = N;
%let codedisthoi = N;
data _null_;
set GroupsDist;
if &loopcount. = _N_;
call symputx('runid', runid);
call symputx('group', group);
call symputx('order', order);
if index(upcase(codedist), "EXP") > 0 then call symputx('codedistexp', 'Y');
if index(upcase(codedist), "HOI") > 0 then call symputx('codedisthoi', 'Y');
run;
/* Aggregate results and keep only relevant distindextype */
proc means data=agg_distindex (where=(lowcase(group)="&group." and runid="&runid.")) noprint nway missing;
var episodes;
class group runid distindextype distindexlist dpidsiteid;
output out=_agg_distindex(drop=_:) sum=;
run;
data _agg_distindex;
set _agg_distindex;
order=&order.;
%if &codedistexp. ne Y %then %do;
if lowcase(distindextype)="exp" then delete;
%end;
%if &codedisthoi. ne Y %then %do;
if lowcase(distindextype)="hoi" then delete;
%end;
run;
proc append data=_agg_distindex base=_distindex force; run;
%end; /*loop through code distribution groups*/
data _distindex (drop = nwords count);
set _distindex;
length ixid $10.;
nwords = countw(distindexlist, '_', 'oq');
do count = 1 to nwords;
ixid = scan(distindexlist, count, '_', 'oq');
if count > 1 then episodes = 0;
output;
end;
run;
/* Create one table for the unique mapping values. If RX, use stockgroup as code */
data _mappingfile (drop = stockgroup _code);
length code $30;
set agg_distindexmap (rename = (code = _code));
if not missing(stockgroup) then do;
codecat = 'RX';
enctype = 'N/A';
codetype = 'N/A';