1

我在下面有一个示例 SAS 代码。我想知道如何使用两种十进制格式报告百分比。例如,我想将 100% 设置为小数点零,而所有其他不是 100% 的百分比都使用 1 个小数点,例如 25.0%。

这是我的代码。

data a;
infile datalines missover;
input subjid trt itt safety pp complete enroll disreason;
uncomplete=(complete^=1);
datalines;
1 1 1 1 1 1 1 
2 2 0 1 1 1 1 
3 1 1 1 1 0 1 4
4 2 1 1 1 1 1 
5 1 1 1 0 0 1 5
6 2 1 1 1 1 1 
7 2 1 1 1 0 1 1
8 1 0 1 0 1 1 
9 1 1 1 1 0 1 5
10 2 0 1 0 0 1 5
11 2 1 1 1 0 1 1
12 2 1 1 0 0 1 2
13 1 1 1 0 0 1 3
14 2 1 1 0 0 1 4
;
run;
data b;
 set a(in=a) a(in=b);
 if b then trt=3;
run;
data c;
 length cat $20;
set b;
 array a(6) itt safety pp complete uncomplete enroll;
 array b(5) r1 r2 r3 r4 r5;
 do i=1 to 6;
 cat=upcase(vname(a(i)));
 value=a(i);
 output;
 end;
 do j=1 to 5;
 if disreason=j then value=1;
 else value=0;
 cat=upcase(vname(b(j)));
 output;
 end;
 keep trt cat value;
run;
proc format ;
 value $newcat(notsorted) 
 'ENROLL'='Enrolled Population'
 '1'='1'
 'PP'='Per-Protocol Population'
 '2'='2'
 'ITT'='ITT Population'
 '3'='3'
 'SAFETY'='Safety Population'
 '4'='4'
 'COMPLETE'='Patients Completed'
 'UNCOMPLETE'='Patients Discontinued'
 '5'='Primary Reason for Discontinuation of Study Dose'
 'R1'='\li360 Lack of Effect'
 'R2'='\li360 Protocol Violation'
 'R3'='\li360 Lost to Follow-up'
 'R4'='\li360 Adverse Event'
 'R5'='\li360 Personal Reason';
value trt 1='Treatment 1'
 2='Treatment 2'
 3='Overall';
picture pct(round) 
 0<-100='0009)'(prefix='(' mult=100)
 0=0;
run;
option missing='' nodate nonumber orientation=landscape;
ods rtf file='c:\dispoistion.rtf';
proc report data=c completerows nowd
 style(report)={frame=hsides rules=groups}
 style(header)={background=white};
 column cat cat2 trt, value, (sum mean);
 define cat/group format=$newcat. preloadfmt order=data noprint;
 define cat2/computed ' ' style(column)={cellwidth=30% PROTECTSPECIALCHARS=OFF 
};
 define trt/across format=trt. '' order=internal;
 define value/analysis '';
 define sum/ 'N' style(column)={cellwidth=35pt} style(header)={just=right};
 define mean/ '(%)' format=pct. style(column)={cellwidth=35pt just=left} 
style(header)={just=left};
 compute cat2/char length=50;
 cat2=put(cat, $newcat.);
 if cat2 in ('1', '2', '3','4') then cat2='';
 endcomp;
run;
ods rtf close;
4

2 回答 2

1

您需要使用图片格式:

data test;
input x;
datalines;
0.5
0.751
0.999
1.00
;;;;
run;

proc format;
picture pct100f
-1 = [PERCENT7.0]
-1<-<1 = [PERCENT7.1]
1 = [PERCENT7.0]
other=[BEST12.];
quit;

proc print data=test;
format x pct100f.;
var x;
run;

根据需要进行调整。-1 <-< 1手段anything that is between -1 and 1, exclusive。_ 告诉它对该[PERCENT7.0]部分使用该格式。

于 2014-08-29T14:40:04.240 回答
0

尝试使用这种格式:

define mean/ '(%)' format=percent7.1
于 2014-08-29T08:40:23.167 回答