请选择 进入手机版 | 继续访问电脑版
楼主: jw21
2929 2

求助,两个data set数据的计算 [推广有奖]

  • 1关注
  • 3粉丝

教授

38%

还不是VIP/贵宾

-

威望
0
论坛币
118940 个
通用积分
0.0528
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2673 点
帖子
109
精华
0
在线时间
2606 小时
注册时间
2008-3-30
最后登录
2024-3-16

jw21 发表于 2015-7-8 03:16:00 |显示全部楼层 |坛友微信交流群
100论坛币
SAS初学者求助,简化后的问题如下:我现在有两个data,a和b。
a为50*5,b为1*2。
现想用a中的每行第4和5列对应减去b中的两个数(再分别进行乘方),
比如如下表,在a中x-0.123 y-0.456,但不要手动在a中减,每次生成的a和b都是不同的,最好是调用变量。
请问如何实现,谢谢!

为了方便理解,再说一下实际问题,数据a50个样本点,5个变量,第4-5变量是每个样本点的xy坐标。数据b是某一个点的xy坐标,想求a中每一个点到该b点的距离。

a:
id m n x y
1xxxx 0.111 0.222
2xxxx 0.333 0.444
…………
…………

b:
x y
0.123 0.456



最佳答案

lambent 查看完整内容

since there are only two variables in table B. you merge table A and B together. It is very easy. data C; merge A B(rename=(x=xb y=yb)); xx = (x-bx)^2; yy = (y-by)^2; run; If your case is more complicated, send me the detail. I hope this will be helpful.
关键词:Data Set 如何实现 实际问题 A50 如何 样本
lambent 在职认证  发表于 2015-7-8 03:16:01 |显示全部楼层 |坛友微信交流群
since there are only two variables in table B. you merge table A and B together. It is very easy.
data C;
merge A B(rename=(x=xb y=yb));
xx = (x-bx)^2;
yy = (y-by)^2;
run;

If your case is more complicated, send me the detail. I hope this will be helpful.
已有 1 人评分论坛币 收起 理由
admin_kefu + 20 热心帮助其他会员

总评分: 论坛币 + 20   查看全部评分

使用道具

忍冬的秋 发表于 2015-8-26 14:56:57 |显示全部楼层 |坛友微信交流群
还可以这样
data a;
infile "C:\360Downloads\test4.csv" missover dsd firstobs =2;
input id m $ n $ x y;
run;
data b;
input x1 y1;
cards;
0.123 0.456
;
run;
data union;
if _n_ =1 then set b;
set a;
run;

使用道具

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

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

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

GMT+8, 2024-3-29 05:52