全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3870 14
2017-03-21
我想请教各位,在SAS里面如果按下面的要求写程序,当一个数据库中 sex=1 与 另一个数据库 gender=1 时,然后当一个数据库中 time=34 和 另一个数据库 agedays=34 匹配时,再生成新变量y=m*s.谢谢各位赐教! 1.png 2.png

二维码

扫码加我 拉你入群

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

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

全部回复
2017-3-21 14:49:44
data table1;
input no gender time;
cards;
55.5 1 34
54.8 1 32
50.0 2 43
58.2 1 43
56.0 2 31
;
data table2;
input sex agedays m s;
cards;
1 33 55.0714 0.03544
1 34 55.2049 0.03539
1 35 55.3374 0.03534
1 37 55.5992 0.03524
1 43 56.1104 0.03496
;

proc sql noprint;
create table table3 as
select
a.sex,
a.agedays,
a.m,
a.s,
m*s as y
from table2 as a
where sex in
(select gender
from table1) and
  agedays in
(select time
from table1);
quit;
二维码

扫码加我 拉你入群

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

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

2017-3-21 15:07:19
zwnSAS121 发表于 2017-3-21 14:49
data table1;
input no gender time;
cards;
非常谢谢亲,还想请教,怎样生成y=(no-m)*s?就是要用到两个表的变量
二维码

扫码加我 拉你入群

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

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

2017-3-21 15:18:04
proc sql noprint;
create table table3 as
select
a.no,
b.sex,
b.agedays,
b.m,
b.s,
m*s as y,
(no-m)*s as y1
from table1 as a,
     table2 as b
where a.gender = b.sex
and   a.time   = b.agedays
;
quit;
二维码

扫码加我 拉你入群

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

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

2017-3-21 17:21:52
zwnSAS121 发表于 2017-3-21 15:18
proc sql noprint;
create table table3 as
select
解决了,非常谢谢亲~希望以后有又不懂的地方,还可以请教~
二维码

扫码加我 拉你入群

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

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

2017-3-22 16:07:43
zwnSAS121 发表于 2017-3-21 14:49
data table1;
input no gender time;
cards;
我还有一个疑问想请教一下,首先,表1的NO1少,表2的NO1多,所以从表2中选出表1中所有的NO1,表2中包含所有表1的NO1,其实就是要求表2的NO1与表1的NO1变量值相同,并保留表2其他所有的变量,而表2还有很多变量,有字符型、日期型和数字型,这个程序在SAS中怎么写?谢谢~
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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