proc sql;
describe table sasuser.demo;
quit;
proc sql;
validate select * from sasuser.demo;
quit;
data plan_2008;
input plancode $ year plan $ cust;
cards;
p101 2008 1min/2rs 450
p201 2008 2min/3rs 560
p207 2008 1min/1ps 660
p345 2008 2min/2rs 640
p420 2008 1min/80p 713
;
data plan_2009;
input plancode $ year plan $ cust;
cards;
p109 2009 1sec/2p 780
p207 2009 1min/1rs 640
p225 2009 1sec/1p 680
p420 2009 1min/80p 750
p431 2009 2sec/1p 790
;
/*union all*/
proc sql;
select * from plan_2008
union all
select * from plan_2009;
quit;
/*union*/
proc sql;
select * from plan_2008
union
select * from plan_2009;
quit;
/*intersect*/
proc sql;
select plancode,plan from plan_2008
intersect
select plancode,plan from plan_2009;
quit;
/*customization*/
proc sql;
select plancode,plan,'available in 2008-2009'as message from plan_2008
intersect
select plancode,plan,'available in 2008-2009' as message from plan_2009;
quit;
/*except*/
proc sql;
select plancode,plan from plan_2008
except
select plancode,plan from plan_2009;
quit;
/*customization*/
proc sql ;
select plancode,plan ,'available in 2008' as message from plan_2008
except
select plancode,plan ,'available in 2008' as message from plan_2009;
quit;
/*multiple operations*/
proc sql;
(select plancode,plan from plan_2008
except
select plancode,plan from plan_2009)
union all
(select plancode,plan from plan_2009
except
select plancode,plan from plan_2008);
quit;
/*customization*/
proc sql;
(select plancode,plan,'avilable in 2008' as message from plan_2008
except
select plancode,plan,'available in 2008' as message from plan_2009)
union all
(select plancode,plan,'avaialable in 2009' as message from plan_2009
except
select plancode,plan,'avialable in 2009' as message from plan_2008);
quit;
proc sql;
select * from plan_2008 where plancode notin (select plancode from plan_2009);
quit;
proc sql;
select * from plan_2009 where plancode notin (select plancode from plan_2008);
quit;
proc sql;
select * from plan_2008 where plancode notin (select plancode from plan_2009)
union all
select * from plan_2009 where plancode notin (select plancode from plan_2008);
quit;
proc sql;
select * from plan_2008 where plancode in (select plancode from plan_2009)
union all
select * from plan_2009 where plancode in (select plancode from plan_2008);
quit;
/*corelated subqueries*/
proc sql;
select * from plan_2009 where plancode in(select plancode from plan_2008)
select * from plan_2008 where (cust<plan_2009cust);
quit;/*error*/
No comments:
Post a Comment