I think you owe me two hundred dollars.
data have;
infile cards truncover;
input Patid $ Visit Drug $ AIEXPR AIFCCL AITRLU HBA1C HBA1CCS ;
datalines;
1 0 A 0 1 1 24 0
1 12 A 1 2 3 65 0
1 24 A 1 3 2 38 0
2 0 B 0 0 0 59 1
2 12 B 1 0 0 62 0
3 0 B 3 3 2 46 0
3 12 B 2 1 1 42 1
3 24 B 1 0 0 36 1
4 0 A 0 1 0 87 0
4 24 A 1 1 2 65 0
5 0 A 0 0 1 46 1
5 12 A 0 0 0 .
5 24 A 3 2 3 34 0
6 0 B 2 2 . 12 1
6 12 B 1 . 1 30 1
;
run;
proc format;
value visit
0='Month 0'
12='Month 12'
24='Month 24'
;
value fmt
.='Missing'
0='Normal'
1='Mild'
2='Moderate'
3='Severe'
;
value order_fmt
.='Missing'
0=' Normal'
1=' Mild'
2=' Moderate'
3=' Severe'
;value $ miss(default=32)
' '='0'
;
value clinic(default=32)
.='Missing'
0='Not Clinically Significant'
1='Clinically Significant'
;
value order_clinic(default=32)
.='Missing'
0=' Not Clinically Significant'
1=' Clinically Significant'
;
run;
%macro var(id=,var=);
%if %upcase(&var.)=HBA1C %then %do;
select &id. as id,
1 as id1,"&var." as a,
2 as id2,catx('|',put(Visit,visit.),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit),')')) as b,
3 as id3,catx('|',catx(' ','Drug',Drug),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit and Drug=a.Drug),')')) as c,
4 as id4,'N' as d,' N' as v,
5 as id5,cats(count(&var.)) as e
from have as a
group by Drug,Visit
union all
select &id. as id,
1 as id1,"&var." as a,
2 as id2,catx('|',put(Visit,visit.),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit),')')) as b,
3 as id3,catx('|',catx(' ','Drug',Drug),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit and Drug=a.Drug),')')) as c,
4 as id4,'Mean (SD)' as d,' Mean (SD)' as v,
5 as id5,catx(' ',put(mean(&var.),8.),cats('(',put(std(&var.),8.1),')')) as e
from have as a
group by Drug,Visit
union all
select &id. as id,
1 as id1,"&var." as a,
2 as id2,catx('|',put(Visit,visit.),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit),')')) as b,
3 as id3,catx('|',catx(' ','Drug',Drug),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit and Drug=a.Drug),')')) as c,
4 as id4,'Median (min,max)' as d,'Median (min,max)' as v,
5 as id5,catx(' ',put(median(&var.),8.),cats('(',put(min(&var.),8.1),',',put(max(&var.),8.1),')')) as e
from have as a
group by Drug,Visit
%end;
%else %do;
select &id. as id,
1 as id1,
%if %upcase(&var.)=HBA1CCS %then %do; "HBAIC Clinical Significance" %end;
%else %do; "&var." %end; as a,
2 as id2,catx('|',put(Visit,visit.),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit),')')) as b,
3 as id3,catx('|',catx(' ','Drug',Drug),cats('(N=',(select count(distinct Patid) from have where Visit=a.visit and Drug=a.Drug),')')) as c,
4 as id4,
%if %upcase(&var.)=HBA1CCS %then %do; put(&var.,clinic.) %end;
%else %do;put(&var.,fmt.)%end; as d,
%if %upcase(&var.)=HBA1CCS %then %do; put(&var.,order_clinic.) %end;
%else %do;put(&var.,order_fmt.)%end; as v,
5 as id5,cats(count(distinct Patid),'(',put(count(distinct Patid)/(select count(distinct Patid) from have where Visit=a.visit and Drug=a.Drug),percent7.1),')') as e
from have as a
group by Drug,Visit,&var.
%end;
%mend;
proc sql;
create table want as
%var(id=1,var=AIEXPR)
union all
%var(id=2,var=AIFCCL)
union all
%var(id=3,var=AITRLU)
union all
%var(id=4,var=HBA1C)
union all
%var(id=5,var=HBA1CCS)
;
quit;
ods rtf file='c:\temp\temp.rtf' style=minimal;
proc report data=want nowd split='|' style={cellpadding=0 cellspacing=0 outputwidth=80%} style(header)={fontweight=bold};
columns id id1 a v d b,c,e;
define id/group noprint;
define id1/group noprint;
define a/group noprint ;
define v/group noprint order=internal missing;
define d/group '' style(column)={asis=on pretext=' '};
define b/across '';
define c/across '' nozero;
define e/group '' format=$miss. style={just=c};
compute before a/style={fontweight=bold just=l background=white};
line a $32.;
endcomp;
run;
ods rtf close;
... View more