英文:
Calculate the percentages by subgroups with proc tabulate
问题
I have the following table:
假设查看Drug3剂量为0.75和1.5。
是否可以使用proc tabulate或其他proc来计算21520 + 34732的百分比?换句话说,0.75的百分比应为21520/(21520 + 34732)=38%,1.5的百分比应为34732/(21520 + 34732)=61%。
谢谢您提前的帮助。
英文:
I have the following table:
Suppose to look at Drug3 dosage 0.75 and 1.5.
Is there a way with proc tabulate or another proc to compute the percentage on 21520 + 34732? In other words, the percentage for 0.75 should be 21520/(21520 + 34732)=38% and for 1.5 should be 34732/(21520 + 34732)=61%
Thank you in advance
答案1
得分: 3
以下是代码的翻译部分:
尝试多标签格式。这里是sashelp.class
的示例:
proc format library=work;
value agef (multilabel notsorted)
11='11'
12='12'
13='13'
11-13='11-13'
14='14'
15='15'
16='16'
14-16='14-16';
value $sexf
'F'='女性'
'M'='男性';
picture myPercent
0-high = '0000009.000%';
run;
proc tabulate data=sashelp.class format=8.1;
class age / mlf preloadfmt order=data;
class sex;
var height;
table age, sex*height*(mean N colPctn*f=myPercent10.2);
format age agef. sex $sexf.;
title 'PROC TABULATE';
run;
这段代码来自以下文章:
https://blogs.sas.com/content/sgf/2016/12/16/creating-and-using-multilabel-formats/
其中包含了对Proc Tabulate
的示例。
这种技术允许你将0.75和1.5分组到一个额外的“虚拟组”中,并获得其结果。
英文:
Try multi-label formats. Here is sashelp.class
example:
proc format library=work;
value agef (multilabel notsorted)
11='11'
12='12'
13='13'
11-13='11-13'
14='14'
15='15'
16='16'
14-16='14-16';
value $sexf
'F'='Female'
'M'='Male';
picture myPercent
0-high = '0000009.000%';
run;
proc tabulate data=sashelp.class format=8.1;
class age / mlf preloadfmt order=data;
class sex;
var height;
table age, sex*height*(mean N colPctn*f=myPercent10.2);
format age agef. sex $sexf.;
title 'PROC TABULATE';
run;
The code is from this article about it:
https://blogs.sas.com/content/sgf/2016/12/16/creating-and-using-multilabel-formats/ with examples for Proc Tabulate
.
This technique will allow you to group 0.75 and 1.5 into an additional "virtual group" and get the result for it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论