常用SAS函数简介
- 格式:ppt
- 大小:796.50 KB
- 文档页数:49
SAS函数汇总范文SAS(Statistical Analysis System)是一种统计分析系统,它提供了一套完整的分析工具和编程语言,用于数据的处理、管理、分析和展示。
SAS提供了多种函数,用于实现各种统计分析方法和数据处理操作。
以下是一些常用的SAS函数汇总:1.数据管理函数-FORMAT函数:用于为数据指定格式,如日期格式、货币格式等。
-LENGTH函数:用于定义变量的长度。
-SORT函数:用于对数据集进行排序。
-DROP函数:用于删除数据集中的一些变量。
-MERGE函数:用于将两个或多个数据集按照相同的变量进行合并。
-DELETE函数:用于删除数据集中的一些观测。
-RENAME函数:用于重命名数据集或变量。
2.数据转换函数-SUBSTR函数:用于提取字符串的子串。
-TRANSLATE函数:用于将字符串中的一些字符替换为其他字符。
-UPCASE函数:将字符串转换为大写。
-LOWCASE函数:将字符串转换为小写。
-PROPCASE函数:将字符串转换为首字母大写,其余字母小写。
-COMPRESS函数:用于去除字符串中的空格或指定字符。
-CAT函数:用于将多个字符串连接成一个字符串。
-INPUT函数:将字符型变量转换为数值型变量。
-PUT函数:将数值型变量转换为字符型变量。
3.数据统计函数-MEAN函数:计算变量的平均值。
-N函数:计算变量的非缺失观测数。
-NMISS函数:计算变量的缺失观测数。
-STD函数:计算变量的标准差。
-VAR函数:计算变量的方差。
-MIN函数:计算变量的最小值。
-MAX函数:计算变量的最大值。
-SUM函数:计算变量的总和。
-FREQ函数:计算变量的频数。
-PROB函数:计算变量的概率密度或累积分布。
4.数据分析函数-REG函数:进行回归分析。
-TTEST函数:进行独立样本t检验。
-ANOVA函数:进行方差分析。
-CORR函数:计算变量之间的相关系数。
-FACTOR函数:进行因子分析。
Functions and CALL Routines by CategoryCategories and Descriptions of Functions Category Function DescriptionArray DIM Returns the number of elements in an arrayHBOUND Returns the upper bound of an arrayLBOUND Returns the lower bound of an arrayBitwise Logical Operations BAND Returns the bitwise logical AND of two argumentsBLSHIFT Returns the bitwise logical left shift of two argumentsBNOT Returns the bitwise logical NOT of an argumentBOR Returns the bitwise logical OR of two argumentsBRSHIFT Returns the bitwise logical right shift of two argumentsBXOR Returns the bitwise logical EXCLUSIVE OR of two argumentsCharacter String Matching CALL RXCHANGE Changes one or more substrings that match a patternCALL RXFREE Frees memory allocated by other regular expression_r(RX) functions and CALL routinesCALL RXSUBSTR Finds the position, length, and score of a substring that matches a patternRXMA TCH Finds the beginning of a substring that matches a pattern and returns a valueRXPARSE Parses a pattern and returns a valueCharacter BYTE Returns one character in the ASCII or the EBCDIC collating sequenceCOLLATE Returns an ASCII or EBCDIC collating sequence character stringCOMPBL Removes multiple blanks from a character stringCOMPRESS Removes specific characters from a character stringDEQUOTE Removes quotation marks from a character valueINDEX Searches a character expression for a string of charactersINDEXC Searches a character expression for specific charactersINDEXW Searches a character expression for a specified string as a wordLEFT Left aligns a SAS character expressionLENGTH Returns the length of an argumentLOWCASE Converts all letters in an argument to lowercaseMISSING Returns a numeric result that indicates whether the argument contains a missing valueQUOTE Adds double quotation marks to a character valueRANK Returns the position of a character in the ASCII or EBCDIC collating sequenceREPEAT Repeats a character expressionREVERSE Reverses a character expressionRIGHT Right aligns a character expressionSCAN Selects a given word from a character expressionSOUNDEX Encodes a string to facilitate searchingSPEDIS Determines the likelihood of two words matching, expressed as the asymmetric spelling distance between the two wordsSUBSTR (left of =) Replaces character value contentsSUBSTR (right of =) Extracts a substring from an argumentTRANSLATE Replaces specific characters in a character expressionTRANWRD Replaces or removes all occurrences of a word in a character stringTRIM Removes trailing blanks from character expressions and returns one blank if the expression is missingTRIMN Removes trailing blanks from character expressions and returns a null string (zero blanks) if the expression is missingUPCASE Converts all letters in an argument to uppercaseVERIFY Returns the position of the first character that is unique to an expressionDBCS KCOMPARE Returns the result of a comparison of character stringsKCOMPRESS Removes specific characters from a character stringKCOUNT Returns the number of double-byte characters in a stringKINDEX Searches a character expression for a string of charactersKINDEXC Searches a character expression for specific charactersKLEFT Left aligns a SAS character expression by removing unnecessary leading DBCS blanks and SO/SIKLENGTH Returns the length of an argumentKLOWCASE Converts all letters in an argument to lowercaseKREVERSE Reverses a character expressionKRIGHT Right aligns a character expression by trimming trailing DBCS blanks and SO/SIKSCAN Selects a given word from a character expressionKSTRCA T Concatenates two or more character stringsKSUBSTR Extracts a substring from an argumentKSUBSTRB Extracts a substring from an argument based on byte positionKTRANSLATE Replaces specific characters in a character expressionKTRIM Removes trailing DBCS blanks and SO/SI from character expressionsKTRUNCATE Truncates a numeric value to a specified lengthKUPCASE Converts all single-byte letters in an argument to uppercaseKUPDATE Inserts, deletes, and replaces character value contentsKUPDATEB Inserts, deletes, and replaces character value contents based on byte unitKVERIFY Returns the position of the first character that is unique to an expressionDate and Time DATDIF Returns the number of days between two datesDA TE Returns the current date as a SAS date valueDA TEJUL Converts a Julian date to a SAS date valueDA TEPART Extracts the date from a SAS datetime valueDA TETIME Returns the current date and time of day as a SAS datetime valueDAY Returns the day of the month from a SAS date valueDHMS Returns a SAS datetime value from date, hour, minute, and secondHMS Returns a SAS time value from hour, minute, and second valuesHOUR Returns the hour from a SAS time or datetime valueINTCK Returns the integer number of time intervals in a given time spanINTNX Advances a date, time, or datetime value by a given interval, and returns a date, time, or datetime valueJULDATE Returns the Julian date from a SAS date valueJULDATE7 Returns a seven-digit Julian date from a SAS date valueMDY Returns a SAS date value from month, day, and year valuesMINUTE Returns the minute from a SAS time or datetime valueMONTH Returns the month from a SAS date valueQTR Returns the quarter of the year from a SAS date valueSECOND Returns the second from a SAS time or datetime valueTIME Returns the current time of dayTIMEPART Extracts a time value from a SAS datetime valueTODAY Returns the current date as a SAS date valueWEEKDAY Returns the day of the week from a SAS date valueYEAR Returns the year from a SAS date valueYRDIF Returns the difference in years between two datesYYQ Returns a SAS date value from the year and quarterDescriptive Statistics CSS Returns the corrected sum of squaresCV Returns the coefficient of variationKURTOSIS Returns the kurtosisMAX Returns the largest valueMEAN Returns the arithmetic mean (average)MIN Returns the smallest valueMISSING Returns a numeric result that indicates whether the argument contains a missing valueN Returns the number of nonmissing valuesNMISS Returns the number of missing valuesORDINAL Returns any specified order statisticRANGE Returns the range of valuesSKEWNESS Returns the skewnessSTD Returns the standard deviationSTDERR Returns the standard error of the meanSUM Returns the sum of the nonmissing argumentsUSS Returns the uncorrected sum of squaresV AR Returns the varianceExternal Files DCLOSE Closes a directory that was opened by the DOPEN function and returns a valueDINFO Returns information about a directoryDNUM Returns the number of members in a directoryDOPEN Opens a directory and returns a directory identifier valueDOPTNAME Returns directory attribute informationDOPTNUM Returns the number of information items that are available for a directoryDREAD Returns the name of a directory memberDROPNOTE Deletes a note marker from a SAS data set or an external file and returns a value FAPPEND Appends the current record to the end of an external file and returns a value FCLOSE Closes an external file, directory, or directory member, and returns a valueFCOL Returns the current column position in the File Data Buffer (FDB)FDELETE Deletes an external file or an empty directoryFEXIST Verifies the existence of an external file associated with a fileref and returns a value FGET Copies data from the File Data Buffer (FDB) into a variable and returns a value FILEEXIST Verifies the existence of an external file by its physical name and returns a valueFILENAME Assigns or deassigns a fileref for an external file, directory, or output device and returns a valueFILEREF Verifies that a fileref has been assigned for the current SAS session and returns a value FINFO Returns the value of a file information itemFNOTE Identifies the last record that was read and returns a value that FPOINT can useFOPEN Opens an external file and returns a file identifier valueFOPTNAME Returns the name of an item of information about a fileFOPTNUM Returns the number of information items that are available for an external file FPOINT Positions the read pointer on the next record to be read and returns a valueFPOS Sets the position of the column pointer in the File Data Buffer (FDB) and returns a valueFPUT Moves data to the File Data Buffer (FDB) of an external file, starting at the FDB's current column position, and returns a valueFREAD Reads a record from an external file into the File Data Buffer (FDB) and returns a valueFREWIND Positions the file pointer to the start of the file and returns a valueFRLEN Returns the size of the last record read, or, if the file is opened for output, returns the current record sizeFSEP Sets the token delimiters for the FGET function and returns a valueFWRITE Writes a record to an external file and returns a valueMOPEN Opens a file by directory id and member name, and returns the file identifier or a 0PATHNAME Returns the physical name of a SAS data library or of an external file, or returns a blankSYSMSG Returns the text of error messages or warning messages from the last data set or external file function executionSYSRC Returns a system error numberExternal Routines CALL MODULE Calls the external routine without any return codeCALL MODULEI Calls the external routine without any return code (in IML environment only)MODULEC Calls an external routine and returns a character valueMODULEIC Calls an external routine and returns a character value (in IML environment only)MODULEIN Calls an external routine and returns a numeric value (in IML environment only)MODULEN Calls an external routine and returns a numeric valueFinancial COMPOUND Returns compound interest parametersCONVX Returns the convexity for an enumerated cashflowCONVXP Returns the convexity for a periodic cashflow stream, such as a bondDACCDB Returns the accumulated declining balance depreciationDACCDBSL Returns the accumulated declining balance with conversion to a straight-line depreciationDACCSL Returns the accumulated straight-line depreciationDACCSYD Returns the accumulated sum-of-years-digits depreciationDACCTAB Returns the accumulated depreciation from specified tablesDEPDB Returns the declining balance depreciationDEPDBSL Returns the declining balance with conversion to a straight-line depreciationDEPSL Returns the straight-line depreciationDEPSYD Returns the sum-of-years-digits depreciationDEPTAB Returns the depreciation from specified tablesDUR Returns the modified duration for an enumerated cashflowDURP Returns the modified duration for a periodic cashflow stream, such as a bondINTRR Returns the internal rate of return as a fractionIRR Returns the internal rate of return as a percentageMORT Returns amortization parametersNETPV Returns the net present value as a fractionNPV Returns the net present value with the rate expressed as a percentagePVP Returns the present value for a periodic cashflow stream, such as a bondSA VING Returns the future value of a periodic savingYIELDP Returns the yield-to-maturity for a periodic cashflow stream, such as a bond Hyperbolic COSH Returns the hyperbolic cosineSINH Returns the hyperbolic sineTANH Returns the hyperbolic tangentMacro CALL EXECUTE Resolves an argument and issues the resolved value for executionCALL SYMPUT Assigns DATA step information to a macro variableRESOLVE Returns the resolved value of an argument after it has been processed by the macrofacilitySYMGET Returns the value of a macro variable during DATA step executionMathematical ABS Returns the absolute valueAIRY Returns the value of the airy functionCNONCT Returns the noncentrality parameter from a chi-squared distributionCOMB Computes the number of combinations of n elements taken r at a time and returns a value CONSTANT Computes some machine and mathematical constants and returns a valueDAIRY Returns the derivative of the airy functionDEVIANCE Computes the deviance and returns a valueDIGAMMA Returns the value of the DIGAMMA functionERF Returns the value of the (normal) error functionERFC Returns the value of the complementary (normal) error functionEXP Returns the value of the exponential functionFACT Computes a factorial and returns a valueFNONCT Returns the value of the noncentrality parameter of an F distributionGAMMA Returns the value of the Gamma functionIBESSEL Returns the value of the modified bessel functionJBESSEL Returns the value of the bessel functionLGAMMA Returns the natural logarithm of the Gamma functionLOG Returns the natural (base e) logarithmLOG10 Returns the logarithm to the base 10LOG2 Returns the logarithm to the base 2MOD Returns the remainder valuePERM Computes the number of permutations of n items taken r at a time and returns a valueSIGN Returns the sign of a valueSQRT Returns the square root of a valueTNONCT Returns the value of the noncentrality parameter from the student's t distributionTRIGAMMA Returns the value of the TRIGAMMA functionProbability CDF Computes cumulative distribution functionsLOGPDF Computes the logarithm of a probability (mass) functionLOGSDF Computes the logarithm of a survival functionPDF Computes probability density (mass) functionsPOISSON Returns the probability from a Poisson distributionPROBBETA Returns the probability from a beta distributionPROBBNML Returns the probability from a binomial distributionPROBBNRM Computes a probability from the bivariate normal distribution and returns a value PROBCHI Returns the probability from a chi-squared distributionPROBF Returns the probability from an F distributionPROBGAM Returns the probability from a gamma distributionPROBHYPR Returns the probability from a hypergeometric distributionPROBMC Computes a probability or a quantile from various distributions for multiple comparisons of means, and returns a valuePROBNEGB Returns the probability from a negative binomial distributionPROBNORM Returns the probability from the standard normal distributionPROBT Returns the probability from a t distributionSDF Computes a survival functionQuantile BETAINV Returns a quantile from the beta distributionCINV Returns a quantile from the chi-squared distributionFINV Returns a quantile from the F distributionGAMINV Returns a quantile from the gamma distributionPROBIT Returns a quantile from the standard normal distributionTINV Returns a quantile from the t distributionRandom Number CALL RANBIN Returns a random variate from a binomial distribution CALL RANCAU Returns a random variate from a Cauchy distributionCALL RANEXP Returns a random variate from an exponential distributionCALL RANGAM Returns a random variate from a gamma distributionCALL RANNOR Returns a random variate from a normal distributionCALL RANPOI Returns a random variate from a Poisson distributionCALL RANTBL Returns a random variate from a tabled probability distributionCALL RANTRI Returns a random variate from a triangular distributionCALL RANUNI Returns a random variate from a uniform distributionNORMAL Returns a random variate from a normal distributionRANBIN Returns a random variate from a binomial distributionRANCAU Returns a random variate from a Cauchy distributionRANEXP Returns a random variate from an exponential distributionRANGAM Returns a random variate from a gamma distributionRANNOR Returns a random variate from a normal distributionRANPOI Returns a random variate from a Poisson distributionRANTBL Returns a random variate from a tabled probabilityRANTRI Random variate from a triangular distributionRANUNI Returns a random variate from a uniform distributionUNIFORM Random variate from a uniform distributionSAS File I/O ATTRC Returns the value of a character attribute for a SAS data setATTRN Returns the value of a numeric attribute for the specified SAS data setCEXIST Verifies the existence of a SAS catalog or SAS catalog entry and returns a valueCLOSE Closes a SAS data set and returns a valueCUROBS Returns the observation number of the current observationDROPNOTE Deletes a note marker from a SAS data set or an external file and returns a valueDSNAME Returns the SAS data set name that is associated with a data set identifierEXIST Verifies the existence of a SAS data library memberFETCH Reads the next nondeleted observation from a SAS data set into the Data Set Data Vector (DDV) and returns a valueFETCHOBS Reads a specified observation from a SAS data set into the Data Set Data Vector (DDV) and returns a valueGETV ARC Returns the value of a SAS data set character variableGETV ARN Returns the value of a SAS data set numeric variableIORCMSG Returns a formatted error message for _IORC_LIBNAME Assigns or deassigns a libref for a SAS data library and returns a valueLIBREF Verifies that a libref has been assigned and returns a valueNOTE Returns an observation ID for the current observation of a SAS data setOPEN Opens a SAS data set and returns a valuePATHNAME Returns the physical name of a SAS data library or of an external file, or returns a blankPOINT Locates an observation identified by the NOTE function and returns a valueREWIND Positions the data set pointer at the beginning of a SAS data set and returns a valueSYSMSG Returns the text of error messages or warning messages from the last data set or external file function executionSYSRC Returns a system error numberV ARFMT Returns the format assigned to a SAS data set variableV ARINFMT Returns the informat assigned to a SAS data set variableV ARLABEL Returns the label assigned to a SAS data set variableV ARLEN Returns the length of a SAS data set variableV ARNAME Returns the name of a SAS data set variableV ARNUM Returns the number of a variable's position in a SAS data setV ARTYPE Returns the data type of a SAS data set variableSpecial ADDR Returns the memory address of a variableCALL POKE Writes a value directly into memoryCALL SYSTEM Submits an operating environment command for executionDIF Returns differences between the argument and its nth lagGETOPTION Returns the value of a SAS system or graphics optionINPUT Returns the value produced when a SAS expression that uses a specified informat expression is readINPUTC Enables you to specify a character informat at run timeINPUTN Enables you to specify a numeric informat at run timeLAG Returns values from a queuePEEK Stores the contents of a memory address into a numeric variablePEEKC Stores the contents of a memory address into a character variablePOKE Writes a value directly into memoryPUT Returns a value using a specified formatPUTC Enables you to specify a character format at run timePUTN Enables you to specify a numeric format at run timeSYSGET Returns the value of the specified operating environment variableSYSPARM Returns the system parameter stringSYSPROD Determines if a product is licensedSYSTEM Issues an operating environment command during a SAS session State and ZIP Code FIPNAME Converts FIPS codes to uppercase state namesFIPNAMEL Converts FIPS codes to mixed case state namesFIPSTATE Converts FIPS codes to two-character postal codesSTFIPS Converts state postal codes to FIPS state codesSTNAME Converts state postal codes to uppercase state namesSTNAMEL Converts state postal codes to mixed case state namesZIPFIPS Converts ZIP codes to FIPS state codesZIPNAME Converts ZIP codes to uppercase state namesZIPNAMEL Converts ZIP codes to mixed case state namesZIPSTA TE Converts ZIP codes to state postal codesTrigonometric ARCOS Returns the arccosineARSIN Returns the arcsineATAN Returns the arctangentCOS Returns the cosineSIN Returns the sineTAN Returns the tangentTruncation CEIL Returns the smallest integer that is greater than or equal to the argumentFLOOR Returns the largest integer that is less than or equal to the argumentFUZZ Returns the nearest integer if the argument is within 1E-12INT Returns the integer valueROUND Rounds to the nearest round-off unitTRUNC Truncates a numeric value to a specified lengthVariable Control CALL LABEL Assigns a variable label to a specified character variableCALL SET Links SAS data set variables to DATA step or macro variables that have the same name and data typeCALL VNAME Assigns a variable name as the value of a specified variableVariable Information V ARRAY Returns a value that indicates whether the specified name is an arrayV ARRAYX Returns a value that indicates whether the value of the specified argument is an arrayVFORMAT Returns the format that is associated with the specified variableVFORMA TD Returns the format decimal value that is associated with the specified variableVFORMA TDX Returns the format decimal value that is associated with the value of the specified argumentVFORMA TN Returns the format name that is associated with the specified variableVFORMA TNX Returns the format name that is associated with the value of the specified argumentVFORMA TW Returns the format width that is associated with the specified variableVFORMA TWX Returns the format width that is associated with the value of the specified argumentVFORMA TX Returns the format that is associated with the value of the specified argumentVINARRAY Returns a value that indicates whether the specified variable is a member of an arrayVINARRAYX Returns a value that indicates whether the value of the specified argument is a member of an arrayVINFORMAT Returns the informat that is associated with the specified variable VINFORMATD Returns the informat decimal value that is associated with the specified variableVINFORMATDX Returns the informat decimal value that is associated with the value of the specified argumentVINFORMATN Returns the informat name that is associated with the specified variableVINFORMATNX Returns the informat name that is associated with the value of the specified argumentVINFORMATW Returns the informat width that is associated with the specified variableVINFORMATWX Returns the informat width that is associated with the value of the specified argumentVINFORMATX Returns the informat that is associated with the value of the specified argument VLABEL Returns the label that is associated with the specified variableVLABELX Returns the variable label for the value of a specified argumentVLENGTH Returns the compile-time (allocated) size of the specified variableVLENGTHX Returns the compile-time (allocated) size for the value of the specified argument VNAME Returns the name of the specified variableVNAMEX Validates the value of the specified argument as a variable nameVTYPE Returns the type (character or numeric) of the specified variableVTYPEX Returns the type (character or numeric) for the value of the specified argumentWeb Tools HTMLDECODE Decodes a string containing HTML numeric character references or HTML character entity references and returns the decoded stringHTMLENCODE Encodes characters using HTML character entity references and returns the encoded stringURLDECODE Returns a string that was decoded using the URL escape syntax URLENCODE Returns a string that was encoded using the URL escape syntax。
SAS常用函数介绍
SAS常用函数介绍
SAS的功能非常强大和全面,这一点在函数上得到了极为充分的体现,SAS 8.2中共有25大类函数,功能涉及到文件管理、金触、数学计算、统计计算、字符串处理、货币转换等各个方面。
因篇幅限制,这里无法将数百种函数一一解释,只列举出饺为常用的十大类函数,关于这些函数的详细信息,以及术列出的货币转换函数、金融函数、地区以及邮政编码函数等相关信息请大家参见SAS帮助。
1.算术函数
2.字符函数
3.数学函数
4.概率与密度函数
5.分位数函数
6.随机函数
7.样本统计函数
8.三角函数
9.截断函数
10.日期时间函数。
第50章 SAS函数简介SAS函数是一个子程序,它由0个或几个自变量返回一个结果值。
每个SAS函数都有一个关键词名字。
为了引用函数,要写出它的名字,然后写出一个自变量或几个自变量,将其用放入括号中,而后这个函数对这些自变量进行某种运算。
SAS函数形式为 functionname (argument ,…)。
本章列举了常用SAS函数10类,以及关于这些函数的信息。
50.1 日期时间函数应用举例【例50-1】计算两个日期之间的天数。
具体SAS程序(程序名为SASTJFX50_1):程序说明data _null_;sdate=’01jan2008’d;edate=’01jan2009’d;days=datdif(sdate,edate,’act/act’); days360=datdif(sdate,edate,’30/360’); put days= days360=;run; 调用datdif函数按每个月实际天数计算按每个月30天计算结果显示为:days=366 days360=360【例50-2】计算两个日期之间的年数。
具体SAS程序(程序名为SASTJFX50_2): 程序说明data _null_;sdate=’01jan1999’d;edate=’01jan2009’d;year1= yrdif(sdate,edate,’30/360’); year2= yrdif(sdate,edate,’act/act’); year3=yrdif(sdate,edate,'act/360'); year4=yrdif(sdate,edate,'act/365'); put year1= year2= year3= year4= ; run; 调用yrdif函数按一年360天一个月30天计算按实际天数计算按一年360天每个月实际天数计算按一年365天每个月实际天数计算结果显示为:year1=10.083333333 year2=10.084931507 year3=10.233333333 year4=10.093150685【例50-3】计算当前时间的小时数和分钟数。
sas单双数函数摘要:一、SAS 单双数函数简介1.函数定义2.函数用途二、SAS 单双数函数的语法与参数1.语法结构2.参数说明三、SAS 单双数函数的实例与应用1.实例演示2.应用场景四、SAS 单双数函数与其他相关函数的比较1.比较对象2.比较结果正文:SAS 单双数函数是SAS 编程中常用的一种函数,用于判断输入的数字是单数还是双数。
该函数在数据处理、统计分析等领域有着广泛的应用。
一、SAS 单双数函数简介SAS 单双数函数的定义很简单,就是判断输入的数字是奇数还是偶数。
在SAS 编程中,我们可以使用这个函数来对一组数据进行分类处理,或者进行一些特定的统计分析。
二、SAS 单双数函数的语法与参数SAS 单双数函数的语法结构如下:```FUNCTION {return_value} = DBLVARIANT(x, y)```其中,x 是输入的数字,y 是可选的参照数。
如果y 指定,那么函数会根据y 来判断x 是单数还是双数;如果没有指定y,那么函数会根据数学规则来判断。
三、SAS 单双数函数的实例与应用假设我们有一组数据,如下所示:```data numbers;input number;datalines;1 2 3 4 5 6 7 8 9 10;```我们可以使用SAS 单双数函数来判断这组数据的数字是单数还是双数,代码如下:```data numbers_class;set numbers;if number mod 2 = 0 then class = "双数";else class = "单数";run;```在这个例子中,我们使用了if 语句来判断数字是单数还是双数,如果是双数,我们就将其分类为"双数",否则就分类为"单数"。
四、SAS 单双数函数与其他相关函数的比较SAS 单双数函数是SAS 编程中的一种基础函数,它主要用于判断数字的奇偶性。
【BaseFunctions】SAS常⽤数学函数ABS(x): 返回x的绝对值BETA(a, b): 返回Beta函数的值。
Beta函数的数学表达式:\(\beta{\left(a,b\right)} = \int_{0}^{1} x^{a-1}(1-x)^{b-1}dx =\frac{\Gamma(a)\Gamma(b)}{\Gamma(a+b)}\)COALESCE(argument-1 <..., argument-n>): 返回参数argument-1, ..., argument-n中的第⼀个⾮缺失值CONSTANT(constant, <, parameter>): 返回⼀些常数数值。
参数constant指定常数名称,参数parameter依赖于参数constant。
DIGAMMA(argument): 返回双伽玛函数的值。
双伽玛(Digamma)函数表达式:\(\Psi(x) = \frac{\Gamma^{'}(x)}{\Gamma(x)}\)ERF(argument): 返回误差函数的值。
误差函数表达式:\(\mathbf{ERF}(x) = \frac{2}{\sqrt{\pi}}\int_{0}^{x}\epsilon^{-z^2} dz\)ERFC(argument): 返回互补误差函数的值。
互补误差函数表达式:\(\mathbf{ERFC}(x) = 1- \frac{2}{\sqrt{\pi}}\int_{0}^{x}\epsilon^{-z^2} dz\)EXP(argument): 返回指数函数的值FACT(n): 返回n的阶乘GAMMA(argument): 返回Gamma函数的值。
Gamma函数表达式:\(\Gamma(x) = \int_0^{\infty} t^{x-1}\epsilon^{-t}dt\)GCD(x1, x2, ..., xn): 返回⼀个或多个整数的最⼤公约数LCM(x1, x2, ..., xn): 返回⼀个或多个整数的最⼩公倍数LGAMMA(argument): 返回Gamma函数的值的⾃然对数。
运用SAS进行Monte Carlo蒙特卡罗模拟(第五弹):SAS常用的随机数函数简介前一篇文章我们介绍了两种产生随机数序列的方法,即随机数函数产生随机数序列,其语法为:var = name(seed,<arg>)和CALL子程序产生随机数序列,其语法为:callname(seed,<arg>,var)。
本节我们将介绍SAS常用的随机数函数(其概率函数我们这里就不作详细介绍,感兴趣的话请查阅相关文献;SAS随机数函数中的seed均为随机数种子):SAS随机数函数分布情况参数说明RANBIN(seed,n,p) 二项分布n:独立实验的次数,p:成功的概率RANCAU(seed) 柯西分布RANEXP(seed) 指数分布RANGAM(seed,a) 伽玛分布 a:a>0,形状参数RANNOR(seed) 正态分布NORMAL(seed) 正态分布RANPOI(seed,m) 泊松分布m:m>0,均值RANTBL(seed,p1,p2,...p n) 离散分布p(i):p(i) >0,且Σp(i)=1,概率RANTRI(seed,h) 三角分布h:0<=h<=1,斜边RANUNI(seed) 均匀分布UNIFORM(seed) 均匀分布这里要注意:Functions RANUNI and UNIFORM are identical. Function UNIFORM cannot be utilized as a CALL routine.文章中还举例说明了用上述基础的SAS随机数函数通过变换,可以产生很多有趣的分布,本人对此没有研究,请大家查看相关文献。
所有的SAS随机数函数都是通过RANUNI随机数函数变换得到的,例如我们通过就可以得到一个正态分布,通过e=-ln(u3)就可以得到指数分布。
通过下面的例子我们可以证明刚才的结论:程序一:DATA TEMP5(DROP=I);DO I=1 TO 12;RUNI=RANUNI(123);OUTPUT;END;RUN;PROC PRINT DATA=TEMP5;RUN;程序二:DATA TEMP6(DROP=I);DO I=1 TO 3;RUNI=RANUNI(123);RNOR=RANNOR(456);REXP=RANEXP(789);OUTPUT;END;RUN;PROC PRINT DATA=TEMP6;RUN;程序一结果:OBS RUNI1 0.750402 0.320913 0.178394 0.906035 0.357126 0.221117 0.786448 0.398089 0.1246710 0.1876911 0.7761812 0.43607程序二结果:OBS RUNI RNOR REXP1 0.75040 0.65572 0.098682 0.35712 0.39428 0.921103 0.12467 0.29958 0.82994从上面的结果我们可以看到,程序二的结果中,变量RUNI的三个值分别对应程序一结果里的程序二结果中的变量RUNI的第一、五、九个值。