久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

表鏈接proc sql的示例分析

164次閱讀
沒有評論

共計 4235 個字符,預計需要花費 11 分鐘才能閱讀完成。

這篇文章給大家分享的是有關表鏈接 proc sql 的示例分析的內容。丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,一起跟隨丸趣 TV 小編過來看看吧。

/*21.1.1  簡單連接 */
proc sql;
select * from resdat.china, resdat.usa;
/*21.1.3  內部連接 */
proc sql;
select * from resdat.china, resdat.usa
where china.level=usa.level;
quit;
/*21.1.3.1  使用表的別名 */
proc sql;
select * from resdat.china as a, resdat.usa as b
where a.level=b.level;
quit;
/*21.1.3.2  使用別名進行表的自我連接 */
proc sql;
select * from resdat.china a, resdat.china b
where a.level b.level;
quit;
/*21.1.3.3  設定連接輸出的排列順序 */
proc sql;
select * from resdat.china a, resdat.china b
where a.level b.level
order by a.level desc;
quit; 
/*21.1.6  缺失值對連接的影響 */
/*  程序一  */
proc sql;
 title   Table A and B Joined 
 select a.obs  A-OBS , a.stkcd, b.obs  B-OBS , b.stkcd
 from a, b
 where a.stkcd= b.stkcd;
/*  程序二  */
proc sql;
 title   Table Three and Four Joined 
 select Three.Obs  3-OBS , Three.Fdcd, Four.Obs  4-OBS , Four.Fdcd
 from Three, Four
 where Three.fdcd= Four.fdcd and 
 three.fdcd is not missing;
/* 21.1.7  從多于兩個表的數據集中查詢數據  */
proc sql outobs=3;
select a.stkcd,b.lstknm,c.clpr
from resdat.sampstk a,resdat.lstkinfo b,resdat.qttndist c
where a.stkcd=b.stkcd and b.stkcd=c.stkcd and a.stkcd=c.stkcd;
quit; 
/* 21.1.8.1  左外部連接  */
proc sql;
select * from resdat.china a left join resdat.usa b
on a.level=b.level;
quit;
/* 21.1.8.2  右外部連接  */
proc sql;
select * from resdat.china a right join resdat.usa b
on a.level=b.level;
quit;
/*21.1.8.3  完全外部連接 */
proc sql;
select * from resdat.china a full join resdat.usa b
on a.level=b.level;
quit;
/*21.1.9.1  與簡單連接功能相同的 Cross 連接  */
proc sql;
select * from resdat.china cross join resdat.usa;
quit;

proc sql; select * from resdat.china union join resdat.usa; quit; /*21.1.9.3 使用自動匹配連接的 Natural 連接 */ proc sql; select * from resdat.china union join resdat.usa; quit; /* 21.1.10  連接使用 COALESCE 函數  */ Proc sql; select a.level,a.china,coalesce(b.level,a.level),coalesce(b.usa,a.china)as usa from resdat.china a full join resdat.usa b on a.level=b.level; quit; 
 title  Table MERGE1  select a.code, a.manager, b.Assitant  from a, b  where a.code=b.code; quit; /* 21.2.2  部分行匹配無重復值的情況  */ /*  程序一  */ data merge2;  merge a b;  by code; proc print data=merge2 noobs;  title  Table MERGE2 /*  程序二 */ proc sql; select code,a.manager,b.assistant  from a natural full join b; quit; /* 21.2.3 有重復值的情況  */ /* 程序一 */ data merge3;  merge a b;  by code; proc print data=merge3 noobs;  title  Table MERGE3 /*  程序二 */ Proc sql; Title  Table Merge3 Select a.code, a.manager, b.assistant  From a full join b  On a.code=b.code; quit;  /* 21.3.1  產生單個值的子查詢  */ Proc sql; Title  Which Manager has the same code as Assistant Chen Select * From a Where code eq (select code from b where assistant= Chen Quit;/* 21.3.2  產生多個值的子查詢  */ Proc sql; select stkcd,lstknm,lstdt from resdat.lstkinfo where stkcd in (select stkcd from resdat.sampstk); quit;  /* 21.3.3  混合子查詢  */ proc sql; select stkcd,yrret from resdat.yrret a  where (select stktype from resdat.lstkinfo b  where a.stkcd=b.stkcd)= A  and  1jan2005 d =date = 31dec2005 quit; /* 21.3.5  子查詢的多重嵌套  */ Proc sql; select stkcd,yrret from resdat.yrret a  where stkcd in (select stkcd from resdat.sampstk b  where stkcd in(select stkcd from resdat.lstkinfo c  where c.stktype= A ))  and  1jan2005 d =date = 31dec2005 quit; /*21.3.6  在 JOIN 連接中使用子查詢 */ proc sql; select a.id,b.id,sqrt((a.x-b.x)**2+(a.y-b.y)**2)as dist from point a,point b  where a.id lt b.id and  calculated dist=(select min(sqrt((c.x-d.x)**2+(c.y-d.y)**2))  from point c,point d  where c.id lt d.id); quit; /*21.5.2  由多個查詢產生非重復觀測  (UNION 算符)*/ /* 程序一 */ proc sql;  title  A UNION B  select * from A  union  select * from B; quit; /*  程序二  */ proc sql;  title  A UNION ALL B  select * from A  union all  select * from B; quit; /*21.5.3  產生只屬于第一個查詢的觀測 (EXCEPT 算符)*/ /* 程序一 */ proc sql;  title  A EXCEPT B  select * from A  except  select * from B; quit; /* 程序二 */ proc sql;  title  A EXCEPT ALL B  select * from A  except all  select * from B; /*21.5.4  從多個查詢中產生公共部分  (INTERSECT 算符)*/ proc sql;  title  A INTERSECT B  select * from A  intersect  select * from B; /*21.5.5  直接連接查詢結果  (OUTER UNION 算符)*/ /* 程序一 */ proc sql;  title  A OUTER UNION B  select * from A  outer union  select * from B;  /* 程序二 */ proc sql;  title  A OUTER UNION CORR B  select * from A  outer union corr  select * from B; /* 21.5.6  特殊的查詢合并方式  */ proc sql;  title  A EXCLUSIVE UNION B  (select * from A  except  select * from B)  union  (select * from B  except  select * from A);

感謝各位的閱讀!關于“表鏈接 proc sql 的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-15發表,共計4235字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 星子县| 连云港市| 湘潭县| 天气| 八宿县| 南充市| 禄丰县| 廊坊市| 大关县| 嘉义市| 乐亭县| 南开区| 北碚区| 福清市| 崇左市| 大连市| 南陵县| 秦安县| 安徽省| 邛崃市| 平南县| 泾阳县| 新和县| 文水县| 霍州市| 射阳县| 吐鲁番市| 安多县| 海原县| 牡丹江市| 客服| 元氏县| 灵宝市| 龙门县| 大同县| 班玛县| 宜昌市| 盘山县| 武安市| 嘉鱼县| 嵊州市|