计算子组的百分比使用 proc tabulate

huangapple go评论99阅读模式
英文:

Calculate the percentages by subgroups with proc tabulate

问题

I have the following table:

计算子组的百分比使用 proc tabulate

假设查看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:

计算子组的百分比使用 proc tabulate

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的示例:

  1. proc format library=work;
  2. value agef (multilabel notsorted)
  3. 11='11'
  4. 12='12'
  5. 13='13'
  6. 11-13='11-13'
  7. 14='14'
  8. 15='15'
  9. 16='16'
  10. 14-16='14-16';
  11. value $sexf
  12. 'F'='女性'
  13. 'M'='男性';
  14. picture myPercent
  15. 0-high = '0000009.000%';
  16. run;
  17. proc tabulate data=sashelp.class format=8.1;
  18. class age / mlf preloadfmt order=data;
  19. class sex;
  20. var height;
  21. table age, sex*height*(mean N colPctn*f=myPercent10.2);
  22. format age agef. sex $sexf.;
  23. title 'PROC TABULATE';
  24. 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:

  1. proc format library=work;
  2. value agef (multilabel notsorted)
  3. 11='11'
  4. 12='12'
  5. 13='13'
  6. 11-13='11-13'
  7. 14='14'
  8. 15='15'
  9. 16='16'
  10. 14-16='14-16';
  11. value $sexf
  12. 'F'='Female'
  13. 'M'='Male';
  14. picture myPercent
  15. 0-high = '0000009.000%';
  16. run;
  17. proc tabulate data=sashelp.class format=8.1;
  18. class age / mlf preloadfmt order=data;
  19. class sex;
  20. var height;
  21. table age, sex*height*(mean N colPctn*f=myPercent10.2);
  22. format age agef. sex $sexf.;
  23. title 'PROC TABULATE';
  24. run;

Output from the code

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.

huangapple
  • 本文由 发表于 2023年4月17日 18:21:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定