日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

sas中的sql(2) 行选择 、限制重复、条件运算符、运行前语法检查、feedback、count...

發(fā)布時(shí)間:2025/3/20 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sas中的sql(2) 行选择 、限制重复、条件运算符、运行前语法检查、feedback、count... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1:獲取數(shù)據(jù)集前幾行觀測

proc sql outobs=5; *outobs選項(xiàng)只限制顯示的行數(shù),并不限制讀入的行數(shù). inobs=選項(xiàng)可以限制讀入的行數(shù);select * from sashelp.class; quit;data res;set sashelp.class (obs=5); run;

2:Eliminating Duplicate Rows from Output ?

DISTINCT :?applies to all columns, and only those columns, that are listed in the SELECT clause.

注意這里一個(gè)細(xì)節(jié),distinct的變量會(huì)默認(rèn)排序

proc sql; select distinct flightnumber, destination /*distinct只能跟在select后*/ from sasuser.internationalflights; quit;

?

3:條件運(yùn)算符

?To create a negative condition, you can precede any of these conditional operators, except for ANY and ALL, with the NOT operator.?

3.1:BETWEEN value-1 AND value-2 ?( between or equal to 兩端的value是被包括進(jìn)去的)

To select rows based on a range of numeric or character values(value可以使數(shù)字也可以是字符),When specifying the limits for the range of values, it is not necessary to specify the smaller value first. (value-1/2的大小無要求

?

3.2:Using the CONTAINS or Question Mark (?) Operator to Select a String ?

sql-expression CONTAINS/? sql-expression?

where sql-expression is a character column, string (character constant), or expression(contain某些東西的列是字符型)

proc sql outobs=10; select name from sasuser.frequentflyers where name contains 'ER'; quit;

?

3.3:IN Operator to Select Values from a List ?

column IN (constant-1 <, . . . constant-n>)?

constant-1 and constant-n represent a list that contains one or more specific values.(括號(hào)中的常量個(gè)數(shù)大于等于1)

?

?

3.4:?IS MISSING or IS NULL Operator to Select Missing Values ?

To select rows that contain missing values, both character and numeric, use the IS MISSING or IS NULL operator. These operators are interchangeable. ?

字符型和數(shù)值型缺失都可檢驗(yàn),這兩個(gè)符號(hào)是等價(jià)的)

where column = ' '; where column = .;分別只能檢驗(yàn)字符型和數(shù)值型缺失。

?

3.5:?LIKE Operator to Select a Pattern?

column LIKE 'pattern' ?

underscore ( _ ) ?any single character?

percent sign (%) ?any sequence of zero or more characters

proc sql; select ffid, name, address from sasuser.frequentflyers where address like '% P%PLACE'; *空格也包含在字符串中; quit;

?

3.6:Using the Sounds-Like (=*) Operator to Select a Spelling Variation?

The sounds-like (=*) operator uses the SOUNDEX algorithm to compare each value of a column (or other sql-expression) with the word or words (or other sql-expression) that you specify.

?

3.7:Subsetting Rows by Using Calculated Values (sas特有的,不是標(biāo)準(zhǔn)sql中的)

sas編譯時(shí),先執(zhí)行where,如果不用calculated那么就會(huì)報(bào)錯(cuò)說沒有total這個(gè)變量,加上后會(huì)在新生成的變量中查找。

proc sql outobs=10; select flightnumber, date, destination, boarded + transferred + nonrevenue as Total,
      calculated Total/2 as half
from sasuser.marchflights where calculated total < 100; /*想要使用新生成的列的時(shí)候,需要加上calculated關(guān)鍵字,having要加 order by 不用加*/

?

3.8:Using the ANY Operator?

where dateofbirth < any ? (subquery...) ? ? ? ? ? ? ?

<any equal to max() ? ?比如,子查詢返回20 、30、 40,那么,外查詢選擇所有<40的記錄

>any equal to min()  ?比如,子查詢返回20 、30、 40,那么,外查詢選擇所有>20的記錄

=any equal to in

?

3.9:Using the ALL Operator?

all和any相反

?

3.10:exsits 、not exsits

對于exsits,為真的話就輸出,假的就不輸出。

對于not exsits相反。

/*需求,選擇是員工又是經(jīng)常單獨(dú)飛行的人姓名*/
proc
sql; title 'Frequent Flyers Who Are Employees';
select name
from sasuser.frequentflyers
where exists
(select * from sasuser.staffmaster
where name=trim(lastname)||', '||firstname)
order by name;
quit;

?

4、NOEXEC 、VALIDATE;

相同點(diǎn):這兩個(gè)關(guān)鍵字都有使程序不執(zhí)行,只進(jìn)行語法檢查的效果!

不同點(diǎn):validate只對緊跟其后的select語句有效,noexec對真?zhèn)€sql過程有效

proc sql noexec; select empid, jobcode, salary from sasuser.payrollmaster where jobcode contains 'NA' order by salary; quit;

proc sql;
validate
select empid, jobcode, salary
  from sasuser.payrollmaster
  where jobcode contains 'NA'
  order by salary;
quit;

?

?4.1 feedback,在列比較多,我用來查看列名。。。。然后復(fù)制粘貼我想要的名字。。。

*options fullstimer=on;*run; proc sql feedback; select * from sashelp.class; NOTE: 語句變換為:select CLASS.Name, CLASS.Sex, CLASS.Age, CLASS.Height, CLASS.Weightfrom SASHELP.CLASS;quit;

?4.2Count

只計(jì)算非缺失值

轉(zhuǎn)載于:https://www.cnblogs.com/yican/p/4079283.html

總結(jié)

以上是生活随笔為你收集整理的sas中的sql(2) 行选择 、限制重复、条件运算符、运行前语法检查、feedback、count...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。