全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3139 2
2015-07-08
悬赏 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.
二维码

扫码加我 拉你入群

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

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

全部回复
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.
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群