楼主: 莫祈缘Hope
8876 3

sas作折线图 [推广有奖]

  • 0关注
  • 0粉丝

小学生

7%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
52 点
帖子
5
精华
0
在线时间
3 小时
注册时间
2016-8-4
最后登录
2017-3-4

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币


就举上表这个例子。

1.       我想做的是各个年龄血压平均值与年龄的折线图,但是表中只有各个调查对象对应的血压值。该如何作图呢?是不是需要生成一个新变量,里面各个年龄对应的值都是该年龄血压的平均值?还是说,不用生成新变量,仅仅靠sbp这个变量也可以做?

2.      做hy这个变量的百分比与年龄的折线图。比如说,年龄为4岁的孩子,hy=1的百分比为66.7%。请问如何用sas如何操作





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:折线图 调查对象 如何操作 百分比 新变量

OZQ(G96QE3W63YM{Y4FJOCC.png (8.11 KB)

OZQ(G96QE3W63YM{Y4FJOCC.png

data.xlsx

9.08 KB

沙发
zwnSAS121 发表于 2017-3-3 15:40:59 |只看作者 |坛友微信交流群
  1. /*解决实际问题之SAS画分组柱状-折线图*/
  2. data sbp;
  3. input id age sbp hy;
  4. cards;
  5. 1        4        70        0
  6. 2        4        75        1
  7. 3        4        73        1
  8. 4        5        76        1
  9. 5        5        80        1
  10. 6        5        78        1
  11. 7        5        58        0
  12. 8        6        80        1
  13. 9        6        90        1
  14. 10        7        76        0
  15. 11        7        90        1
  16. 12        7        98        1
  17. 13        8        89        0
  18. ;

  19. proc sql noprint;
  20. create table test1 as
  21. select mean(sbp) as sbp_mean,
  22. age
  23. from sbp
  24. group by age
  25. order by age
  26. ;
  27. quit;

  28. proc sql noprint;
  29. create table test2 as
  30. select count(hy) as hy1,
  31. age
  32. from sbp
  33. where hy=1
  34. group by age;
  35. quit;

  36. proc sql noprint;
  37. create table test3 as
  38. select count(hy) as hy0,
  39. age
  40. from sbp
  41. where hy=0
  42. group by age;
  43. quit;

  44. proc sort data=test2;by age;run;
  45. proc sort data=test3;by age;run;
  46. data test4;
  47. merge test2 test3;
  48. by age;
  49. if hy0=. then hy0=0;
  50. else if hy1=. then hy1=0;
  51. percent=hy1/(hy0+hy1);
  52. format percent percent8.2;
  53. run;

  54. /*SAS 9.4 M2*/
  55. proc sgplot data=test1 noautolegend;
  56.   series x=age y=sbp_mean /
  57.          lineattrs=(thickness=2 color="#00b8e5") dataskin=pressed
  58.          markers markerattrs=(symbol=trianglefilled color=red size=10);
  59.                  yaxis ranges=(0-90) label="sbp平均水平";
  60.                  xaxis label="年龄";
  61. run;

  62. /*SAS 9.4 M3*/
  63. proc sgplot data=test1 noautolegend;
  64. vbarbasic age / response=sbp_mean dataskin=gloss fillattrs=(color="#00bc57")
  65.          baselineattrs=(thickness=0) barwidth=0.7;
  66.   series x=age y=sbp_mean / arrowheadpos=end arrowheadshape=filled
  67.          lineattrs=(thickness=5 color="#00b8e5") dataskin=pressed
  68.                  markers markerattrs=(symbol=circlefilled color=red size=15);
  69.                  yaxis label="sbp平均水平";
  70.                  xaxis label="年龄";
  71. run;

  72. /*SAS 9.4 M2*/
  73. proc sgplot data=test4 noautolegend;
  74.   series x=age y=percent /
  75.          lineattrs=(thickness=5 color="#00bc57") dataskin=pressed
  76.                  markers markerattrs=(symbol=circlefilled color=red size=15);
  77.                  yaxis label="hy=1的百分比";
  78.                  xaxis label="年龄";
  79. run;

  80. /*SAS 9.4 M3*/
  81. proc sgplot data=test4 noautolegend;
  82. vbarbasic age / response=percent dataskin=gloss fillattrs=(color="#00bc57")
  83.          baselineattrs=(thickness=0) barwidth=0.7;
  84.   series x=age y=percent / arrowheadpos=end arrowheadshape=filled
  85.          lineattrs=(thickness=5 color="#00b8e5") dataskin=pressed
  86.                  markers markerattrs=(symbol=circlefilled color=red size=10);
  87.                  yaxis label="hy=1的百分比";
  88.                  xaxis label="年龄";
  89. run;
复制代码

使用道具

藤椅
莫祈缘Hope 发表于 2017-3-3 21:43:33 |只看作者 |坛友微信交流群
zwnSAS121 发表于 2017-3-3 15:40
真是太感谢了,我自己消化消化

使用道具

板凳
zwnSAS121 发表于 2017-3-4 10:41:39 |只看作者 |坛友微信交流群
  1. proc sgplot data=sbp noautolegend;
  2. vbar age / response=sbp stat=mean limitstat=clm alpha=0.05
  3. limitattrs=(color=red thickness=2)
  4. barwidth=0.3 fillattrs=(color="#00bc57");
  5. xaxis valueattrs=(size=12) label="年龄" labelattrs=(size=12);
  6. yaxis valueattrs=(size=12) label="sbp平均值" labelattrs=(size=12);
  7. run;
复制代码

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 00:01