data b;
input ID;
cards;
001
002
003
004
005
006
;
proc sql;
create table result as
select id,1 as var1 from account where id in (select id from a )
union
select id ,0 as var1 from account where id not in (select id from a);
create table result as
select id ,var1,1 as var2 from result where id in (select id from b)
union
select id ,var1 ,0 as var2 from result where id not in (select id from b);
quit;
proc print;
run;作者: shiyiming 时间: 2010-10-30 19:40 标题: Re: 问一个根据多个表生成数据的问题 hopewell确实写的好
SQL实现我写了一个
不过感觉还可以优化一下作者: shiyiming 时间: 2010-10-31 10:10 标题: Re: 问一个根据多个表生成数据的问题 两位都是高手,谢谢~ <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->作者: shiyiming 时间: 2010-11-1 23:05 标题: Re: 问一个根据多个表生成数据的问题 to ganshenme
like SASsy way to code this:
proc sql;
create view accountv as
select * from account order by id;
create view av as
select * from a order by id;
create view bv as
select * from b order by id;
quit;
data new;
merge accountv(in=_1) av(in=_a) bv(in=_b);
by ID;
var1=(_a=1); var2=(_b=1);
if _1;
run;作者: shiyiming 时间: 2010-11-21 23:57 标题: Re: 问一个根据多个表生成数据的问题 [code:2z03jzxr]
/*STEP1: CREATE A FORMAT TO INDICATE Y/N*/
proc format;
value define . = 0
other = 1
;
run;
/*STEP2: LEFT JOIN THE THREE TABLES*/
proc sql;
select account.id, a.id as var1 format=define., b.id as var2 format=define.
from account left join a on account.id = a.id
left join b on account.id = b.id
;
quit;
********************TEST PASSED***********************;
[/code:2z03jzxr]作者: shiyiming 时间: 2010-11-22 00:17 标题: Re: 问一个根据多个表生成数据的问题 to oloolo
原来data step也能merge三个dataset啊,受教了。作者: shiyiming 时间: 2010-11-22 09:57 标题: Re: 问一个根据多个表生成数据的问题 小弟也试着写了一下上面的程序,请高手指正哈~-~
[code:r878dgef]data account;
input ID;
cards;
001
002
003
004
005
006
007
008
009
;
data a;
input ID;
cards;
001
002
003
007
008
009
;
data b;
input ID;
cards;
001
002
003
004
005
006
;
proc sql;
create table result as
select id,id in(select id from a) as var1,id in(select id from b) as var2
from account;
quit;[/code:r878dgef]