新聞中心
SAS具有多種內(nèi)置函數(shù),有助于分析和處理數(shù)據(jù)。 這些函數(shù)用作DATA語(yǔ)句的一部分。 它們將數(shù)據(jù)變量作為參數(shù),并將結(jié)果存儲(chǔ)到另一個(gè)變量中。 根據(jù)函數(shù)的類型,所需的參數(shù)數(shù)量可能會(huì)有所不同。 一些函數(shù)接受零參數(shù),而另一些函數(shù)接受固定數(shù)量的變量。 以下是SAS提供的功能類型列表。

句法
在SAS中使用函數(shù)的一般語(yǔ)法如下。
FUNCTIONNAME(argument1, argument2...argument)
這里的參數(shù)可以是常量,變量,表達(dá)式或另一個(gè)函數(shù)。
功能分類
根據(jù)它們的使用情況,在SAS中的功能被分類為如下。
- 數(shù)學(xué)
- 日期和時(shí)間
- 字符
- 舍去
- 雜
數(shù)學(xué)函數(shù)
這些是用于對(duì)變量值應(yīng)用一些數(shù)學(xué)計(jì)算的函數(shù)。
例子
下面的SAS程序顯示了一些重要的數(shù)學(xué)函數(shù)的使用。
data Math_functions; v1=21; v2=42; v3=13; v4=10; v5=29; /* Get Maximum value */ max_val = MAX(v1,v2,v3,v4,v5); /* Get Minimum value */ min_val = MIN (v1,v2,v3,v4,v5); /* Get Median value */ med_val = MEDIAN (v1,v2,v3,v4,v5); /* Get a random number */ rand_val = RANUNI(0); /* Get Square root of sum of the values */ SR_val= SQRT(sum(v1,v2,v3,v4,v5)); proc print data = Math_functions noobs; run;
當(dāng)上面的代碼運(yùn)行時(shí),我們得到以下輸出:
日期和時(shí)間函數(shù)
這些是用于處理日期和時(shí)間值的函數(shù)。
例子
下面的SAS程序顯示了使用日期和時(shí)間的函數(shù)。
data date_functions;
INPUT @1 date1 date9. @11 date2 date9.;
format date1 date9. date2 date9.;
/* Get the interval between the dates in years*/
Years_ = INTCK('YEAR',date1,date2);
/* Get the interval between the dates in months*/
months_ = INTCK('MONTH',date1,date2);
/* Get the week day from the date*/
weekday_ = WEEKDAY(date1);
/* Get Today's date in SAS date format */
today_ = TODAY();
/* Get current time in SAS time format */
time_ = time();
DATALINES;
21OCT2000 16AUG1998
01MAR2009 11JUL2012
;
proc print data = date_functions noobs;
run;
當(dāng)運(yùn)行上面的代碼,我們得到以下的輸出:
字符函數(shù)
這些都是用于處理字符或文本值的功能。
例子
下面的SAS程序顯示了使用的字符函數(shù)。
data character_functions;
/* Convert the string into lower case */
lowcse_ = LOWCASE('HELLO');
/* Convert the string into upper case */
upcase_ = UPCASE('hello');
/* Reverse the string */
reverse_ = REVERSE('Hello');
/* Return the nth word */
nth_letter_ = SCAN('Learn SAS Now',2);
run;
proc print data = character_functions noobs;
run;
當(dāng)運(yùn)行上面的代碼,我們得到以下的輸出:
截?cái)喙δ?/h2>
這些是用于截?cái)鄶?shù)字值的功能。
例子
下面的SAS程序說(shuō)明了如何使用截?cái)喙δ堋?/p>
data trunc_functions; /* Nearest greatest integer */ ceil_ = CEIL(11.85); /* Nearest greatest integer */ floor_ = FLOOR(11.85); /* Integer portion of a number */ int_ = INT(32.41); /* Round off to nearest value */ round_ = ROUND(5621.78); run; proc print data = trunc_functions noobs; run;
當(dāng)運(yùn)行上面的代碼,我們得到以下的輸出:
其它功能
例子
下面的SAS程序顯示了使用的輔助功能。
data misc_functions;
/* Nearest greatest integer */
state2=zipstate('01040');
/* Amortization calculation */
payment=mort(50000, . , .10/12,30*12);
proc print data = misc_functions noobs;
run;
當(dāng)運(yùn)行上面的代碼,我們得到以下的輸出:
本文題目:創(chuàng)新互聯(lián)SAS教程:SAS功能
本文URL:http://www.5511xx.com/article/dhpchog.html


咨詢
建站咨詢
