楼主: liyichen17
12395 8

[问答] 请问:如何画出这样的直方图? [推广有奖]

  • 4关注
  • 1粉丝

讲师

3%

还不是VIP/贵宾

-

威望
0
论坛币
5 个
通用积分
1.0166
学术水平
4 点
热心指数
5 点
信用等级
2 点
经验
19465 点
帖子
165
精华
0
在线时间
602 小时
注册时间
2012-2-28
最后登录
2022-12-20

楼主
liyichen17 在职认证  发表于 2012-12-2 16:27:39 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我有两个变量,一个是year,另一个是age,怎样画出下面的图形(08年与09年各阶段年龄构成的比较)?颜色什么的不用考虑。。。
QQ截图20121202161818.jpg
二维码

扫码加我 拉你入群

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

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

关键词:直方图 year ear Age 如何 直方图

回帖推荐

ziyenano 发表于8楼  查看完整内容

用个笨方法,算出每个年龄段占每年所有人群的百分比~ ods listing close; ods output CrossTabFreqs=t2(keep=age year colpercent where=(colpercent is not missing)); proc freq data=t1; table age*year/nopercent norow nofreq; run; ods listing; proc gchart data=t2; vbar year/group=age discrete patternid=midpoint sumvar=colpercent type=mean; run;

沙发
line_us 发表于 2012-12-2 20:39:10
用EXCEL很简单就可以实现,
具体参考excel图表向导。

藤椅
liyichen17 在职认证  发表于 2012-12-2 21:03:30
line_us 发表于 2012-12-2 20:39
用EXCEL很简单就可以实现,
具体参考excel图表向导。
那SAS中如何实现呢?

板凳
bobguy 发表于 2012-12-3 00:57:16
Here is a prototype of the sgplot with vbar. I think you need a version SAS 9.2 or higher.

data t1;

      do age='1). <20  ', '2). 20-40','3). 40-60','4). 60-80','5). 80+';
             POP=abs( (age='1). <20  ')*1*rannor(123)+
             (age='2). 20-40')*3*rannor(123)+
             (age='3). 40-60')*3*rannor(123)+
             (age='4). 60-80')*2*rannor(123)+
             (age='5). 80+  ')*0.5*rannor(123));
                         year=2008;
                 output;
                 pop=pop+abs(rannor(123)*0.3);
                 year=2012;
                 output;
                end;

run;


proc sgplot data=t1;
  yaxis label="POPULATION (10 M.)" ;
  vbar AGE / response=POP GROUP= year GROUPDISPLAY= CLUSTER
;
run;

报纸
liyichen17 在职认证  发表于 2012-12-3 10:14:32
bobguy 发表于 2012-12-3 00:57
Here is a prototype of the sgplot with vbar. I think you need a version SAS 9.2 or higher.

data  ...
Damn it! I am using SAS 9.1, how can I do that with SAS 9.1?

地板
ziyenano 发表于 2012-12-3 10:25:28
proc gchart data=t1;
vbar year/group=age discrete patternid=midpoint ;
run;

7
liyichen17 在职认证  发表于 2012-12-3 13:41:44
ziyenano 发表于 2012-12-3 10:25
proc gchart data=t1;
vbar year/group=age discrete patternid=midpoint ;
run;
你好,我已经把age分为10组,即_age(‘0-10’、‘11-20’...‘91-100’),用以下code:
  1. proc gchart data=t1;
  2. vbar year/group=_age
  3.               type=pct
  4.               discrete
  5.               patternid=midpoint ;
  6. run;
复制代码
得到: chart.jpg
--------------------------------------------------------------------
可是我发现,如在‘0-10’组中2009年占三年所有人群1%,我想要的是每个年龄组占每年所有人群的percent(如一楼的图那样)。怎么来实现呢?

8
ziyenano 发表于 2012-12-3 14:12:45
用个笨方法,算出每个年龄段占每年所有人群的百分比~
ods listing close;
ods output CrossTabFreqs=t2(keep=age year colpercent where=(colpercent is not missing));
proc freq data=t1;
table age*year/nopercent norow nofreq;
run;
ods listing;

proc gchart data=t2;
vbar year/group=age discrete patternid=midpoint sumvar=colpercent type=mean;
run;

9
liyichen17 在职认证  发表于 2012-12-3 14:28:09
ziyenano 发表于 2012-12-3 14:12
用个笨方法,算出每个年龄段占每年所有人群的百分比~
ods listing close;
ods output CrossTabFreqs=t2(k ...
非常感谢,我试一下。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 10:18