****************************************************************************************************
****************************************************************************************************
* PROGRAM: codedistribution_output.sas
* Created (mm/dd/yyyy): 04/16/2021
*--------------------------------------------------------------------------------------------------
* PURPOSE: The macro creates both the Full Code Distribution and Total Code Counts output
*--------------------------------------------------------------------------------------------------
* Sentinel Coordinating Center
* info@sentinelsystem.org
***************************************************************************************************;
%macro codedistribution_output;
/* This macros produces output for a specific distribution type (EXP or HOI) */
%macro codedistribution_type(distindextype=);
/* Compute group label to display in title */
%isdata(dataset=labelfile);
%if %eval(&nobs>0) %then %do;
select label into :grouplabel trimmed from labelfile
where lower(group)="&group." and runid = "&runid" and
%if &distindextype. eq exp %then %do;
lower(labeltype)="grouplabel";
lower(labeltype)="outcomelabel";
%if %str("&grouplabel.") eq %str("") %then %let grouplabel = %trim(&group.);
/* Compute Total Code Counts (must be processed first to restrict to topncodedist */
proc sort data=codedistdata (where=(lower(group) = "&group." and runid = "&runid" and lower(distindextype) = "&distindextype."))
out=codedistcounts (keep = runid distindexlist code description codetype codecat codetype totalN);
by distindexlist descending totalN code;
by distindexlist descending totalN code;
if first.distindexlist then do;