Calculate new variables using the sum of other columns in PROC REPORT

This post was kindly contributed by SAS & Statistics - go there to comment and to read the full post.

%macro vol(type,desc);

proc report data=fmxx center headline headskip split=’/’;
&nbsp &nbsp &nbsp column site_id havevis &type.2 &type.3 &type.p1 &type.p2;

&nbsp &nbsp &nbsp define site_id / group id order=internal width=16 left ‘Clinical Center’style(header)={cellwidth= 1.2in just=left} style(column)={cellwidth= 1.2in cellheight=0.17in just=left};
&nbsp &nbsp &nbsp define havevis / sum style(header)={cellwidth=.9in} ‘All/Visits’ center ;
&nbsp &nbsp &nbsp define &type.2 / sum style(header)={cellwidth=.9in} width=15 “Any/&desc” center ;
&nbsp &nbsp &nbsp define &type.3 / sum style(header)={cellwidth=.9in} width=15 “3+ Volumes/for &desc/n” center ;
&nbsp &nbsp &nbsp define &type.p1 / computed width=10 format=5.1 “3+ Volumes/for &desc/% (1)” center;
&nbsp &nbsp &nbsp define &type.p2 / computed width=10 format=5.1 “3+ Volumes/for &desc/% (2)” center;

&nbsp &nbsp &nbsp compute &type.p1;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &type.p1=(&type.3.sum*100)/&type.2.sum;
&nbsp &nbsp &nbsp endcomp;
&nbsp &nbsp &nbsp compute &type.p2;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &type.p2=(&type.3.sum*100)/havevis.sum;
&nbsp &nbsp &nbsp endcomp;
title1 ” “;
run;

%mend;

%vol(head, Head);

If data is already summarized, use the following code for compute:

&nbsp &nbsp &nbsp compute &type.p1;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _c5_=(_c4_*100)/_c3_;
&nbsp &nbsp &nbsp endcomp;
&nbsp &nbsp &nbsp compute &type.p2;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _c6_=(_c4_*100)/_c2_;
&nbsp &nbsp &nbsp endcomp;

This post was kindly contributed by SAS & Statistics - go there to comment and to read the full post.