楼主: waitalone11
11405 10

[原创博文] 求助 如何增加一列 [推广有奖]

  • 0关注
  • 1粉丝

博士生

88%

还不是VIP/贵宾

-

威望
0
论坛币
150 个
通用积分
0.0034
学术水平
7 点
热心指数
9 点
信用等级
3 点
经验
21116 点
帖子
93
精华
0
在线时间
637 小时
注册时间
2008-12-14
最后登录
2022-4-13

楼主
waitalone11 发表于 2010-2-2 21:46:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
data  a;
input a $ b;
cards;
a 1
b 2
c 3
d 4
;
run;

我想添加一列,新的一列是b 的各个观测值占该列总和的比。谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:cards Input card Data Run 如何

回帖推荐

bobguy 发表于6楼  查看完整内容

There are many ways, SAS SQL provides a simple way. data a; input a $ b; cards; a 1 b 2 c 3 d 4 ; run; proc sql; select *, b/sum(b) as pct from a; quit;

grantdxl 发表于4楼  查看完整内容

有一个笨办法: data b; set a; sumb+b; run; 得到总和后,假定为X data c; set b; c=b/x; run;

bobguy 发表于9楼  查看完整内容

But you will have to read twice, one for calculating a total and the other for calculating a percent. Here it is. This sort of programming style is posted several times.There are some good knowledge points here. data a; input a $ b; cards; a 1 b 2 c 3 d 4 ; run; data b; do _n_=1 to nobs; set a nobs=nobs; tot_b+b; end; do _n_=1 to nobs; se ...

本帖被以下文库推荐

沙发
chenxiaoliang22 在职认证  发表于 2010-2-2 21:48:45
这是要在什么软件里操作啊

藤椅
waitalone11 发表于 2010-2-2 22:24:19
SAS 里 2# chenxiaoliang22

板凳
grantdxl 发表于 2010-2-3 00:44:05
有一个笨办法:
data b;
set a;
sumb+b;
run;
得到总和后,假定为X
data c;
set b;
c=b/x;
run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

力拔山兮气盖世,时不利兮锥不逝

报纸
Stickerr 发表于 2010-2-3 01:39:12
1# waitalone11


proc freq data=a; weight b; table a/out=a2; run;

dataset a2 will be the dataset you are asking for.

地板
bobguy 发表于 2010-2-3 06:04:01
waitalone11 发表于 2010-2-2 21:46
data  a;
input a $ b;
cards;
a 1
b 2
c 3
d 4
;
run;

我想添加一列,新的一列是b 的各个观测值占该列总和的比。谢谢!
There are many ways, SAS SQL provides a simple way.

data  a;
input a $ b;
cards;
a 1
b 2
c 3
d 4
;
run;

proc sql;
  select *, b/sum(b) as pct
  from a;
  quit;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

7
xuwei2007 发表于 2010-2-3 08:36:01

data  a;
input a $ b;
cards;
a 1
b 2
c 3
d 4
;
run;
proc sql;
  create table b as
  select *, b/sum(b) as pct format=percent8.
  from a;
  quit;

8
waitalone11 发表于 2010-2-3 09:36:49
如果是在同一个DATA步里实现的话该怎么写程序?谢谢!

9
bobguy 发表于 2010-2-3 10:57:24
waitalone11 发表于 2010-2-3 09:36
如果是在同一个DATA步里实现的话该怎么写程序?谢谢!
But you will have to read twice, one for calculating a total and the other for calculating a percent.

Here it is. This sort of programming style  is posted several times.There are some good knowledge points here.

data  a;
input a $ b;
cards;
a 1
b 2
c 3
d 4
;
run;

data b;
   do _n_=1 to nobs;
       set a nobs=nobs;
       tot_b+b;
   end;
   do _n_=1 to nobs;
       set a ;
       pct=b/tot_b;
       output;
   end;
run;

proc print; run;

proc sql;
  select *, b/sum(b) as pct
  from a;
  quit;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

10
crackman 发表于 2010-5-21 23:44:25
学习了

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 12:17