课程表

SAS 基础

SAS 数据集操作

SAS 数据展示

SAS 基本统计程序

工具箱
速查手册

SAS功能

当前位置:免费教程 » 大数据/云 » SAS

SAS具有多种内置函数,有助于分析和处理数据。 这些函数用作DATA语句的一部分。 它们将数据变量作为参数,并将结果存储到另一个变量中。 根据函数的类型,所需的参数数量可能会有所不同。 一些函数接受零参数,而另一些函数接受固定数量的变量。 以下是SAS提供的功能类型列表。

句法

在SAS中使用函数的一般语法如下。

  1. FUNCTIONNAME(argument1, argument2...argumentn)

这里的参数可以是常量,变量,表达式或另一个函数。

功能分类

根据它们的使用情况,在SAS中的功能被分类为如下。

  • 数学
  • 日期和时间
  • 字符
  • 舍去

数学函数

这些是用于对变量值应用一些数学计算的函数。

例子

下面的SAS程序显示了一些重要的数学函数的使用。

  1. data Math_functions;
  2. v1=21; v2=42; v3=13; v4=10; v5=29;
  3.  
  4. /* Get Maximum value */
  5. max_val = MAX(v1,v2,v3,v4,v5);
  6.  
  7. /* Get Minimum value */
  8. min_val = MIN (v1,v2,v3,v4,v5);
  9.  
  10. /* Get Median value */
  11. med_val = MEDIAN (v1,v2,v3,v4,v5);
  12.  
  13. /* Get a random number */
  14. rand_val = RANUNI(0);
  15.  
  16. /* Get Square root of sum of the values */
  17. SR_val= SQRT(sum(v1,v2,v3,v4,v5));
  18.  
  19. proc print data = Math_functions noobs;
  20. run;

当上面的代码运行时,我们得到以下输出:

日期和时间函数

这些是用于处理日期和时间值的函数。

例子

下面的SAS程序显示了使用日期和时间的函数。

  1. data date_functions;
  2. INPUT @1 date1 date9. @11 date2 date9.;
  3. format date1 date9. date2 date9.;
  4.  
  5. /* Get the interval between the dates in years*/
  6. Years_ = INTCK('YEAR',date1,date2);
  7.  
  8. /* Get the interval between the dates in months*/
  9. months_ = INTCK('MONTH',date1,date2);
  10.  
  11. /* Get the week day from the date*/
  12. weekday_ = WEEKDAY(date1);
  13.  
  14. /* Get Today's date in SAS date format */
  15. today_ = TODAY();
  16.  
  17. /* Get current time in SAS time format */
  18. time_ = time();
  19. DATALINES;
  20. 21OCT2000 16AUG1998
  21. 01MAR2009 11JUL2012
  22. ;
  23. proc print data = date_functions noobs;
  24. run;

当运行上面的代码,我们得到以下的输出:

字符函数

这些都是用于处理字符或文本值的功能。

例子

下面的SAS程序显示了使用的字符函数。

  1. data character_functions;
  2.  
  3. /* Convert the string into lower case */
  4. lowcse_ = LOWCASE('HELLO');
  5. /* Convert the string into upper case */
  6. upcase_ = UPCASE('hello');
  7. /* Reverse the string */
  8. reverse_ = REVERSE('Hello');
  9. /* Return the nth word */
  10. nth_letter_ = SCAN('Learn SAS Now',2);
  11. run;
  12.  
  13. proc print data = character_functions noobs;
  14. run;

当运行上面的代码,我们得到以下的输出:

截断功能

这些是用于截断数字值的功能。

例子

下面的SAS程序说明了如何使用截断功能。

  1. data trunc_functions;
  2.  
  3. /* Nearest greatest integer */
  4. ceil_ = CEIL(11.85);
  5. /* Nearest greatest integer */
  6. floor_ = FLOOR(11.85);
  7. /* Integer portion of a number */
  8. int_ = INT(32.41);
  9. /* Round off to nearest value */
  10. round_ = ROUND(5621.78);
  11. run;
  12.  
  13. proc print data = trunc_functions noobs;
  14. run;

当运行上面的代码,我们得到以下的输出:

其它功能

例子

下面的SAS程序显示了使用的辅助功能。

  1. data misc_functions;
  2.  
  3. /* Nearest greatest integer */
  4. state2=zipstate('01040');
  5. /* Amortization calculation */
  6. payment=mort(50000, . , .10/12,30*12);
  7.  
  8. proc print data = misc_functions noobs;
  9. run;

当运行上面的代码,我们得到以下的输出:

转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号