SAS 常用函数汇总
SAS函数汇总范文
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函数:进行因子分析。
SAS函数介绍
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的功能非常强大和全面,这一点在函数上得到了极为充分的体现,SAS 8.2中共有25大类函数,功能涉及到文件管理、金触、数学计算、统计计算、字符串处理、货币转换等各个方面。
因篇幅限制,这里无法将数百种函数一一解释,只列举出饺为常用的十大类函数,关于这些函数的详细信息,以及术列出的货币转换函数、金融函数、地区以及邮政编码函数等相关信息请大家参见SAS帮助。
1.算术函数
2.字符函数
3.数学函数
4.概率与密度函数
5.分位数函数
6.随机函数
7.样本统计函数
8.三角函数
9.截断函数
10.日期时间函数。
SAS函数全量(齐全)
CAT Function Does not remove leading or trailing blanks, and returns a concatenated character string.
COMPARE Function Returns the position of the leftmost character by which two strings differ, or returns 0 if there is no difference.
COMPBL Function Removes multiple blanks from a character string.
COALESCEC Function Returns the first non-missing value from a list of character arguments.
COLLATE Function Returns a character string in ASCII or EBCDIC collating sequence.
ANYSPACE Function Searches a character string for a white-space character (blank, horizontal and vertical tab, carriage return, line feed, and form feed), and returns the first position at which that character is found.
sas 循环函数
sas 循环函数1. DO循环:SAS中最基本也是最常用的循环函数是DO循环。
它允许用户按照给定的次数重复执行一段代码。
DO循环的语法如下:```DO index_variable = start_value TO stop_value BY increment_value;/* 重复执行的代码 */END;```在这个循环中,index_variable是循环索引变量,start_value是索引的起始值,stop_value是索引的结束值,increment_value是每次循环迭代中索引的增量。
例如,下面的代码将打印1到10之间所有的奇数:```DATA test;DO i = 1 TO 10 BY 2;IF mod(i, 2) = 1 THENPUT i;END;RUN;2. DO WHILE循环:DO WHILE循环是一种基于条件的循环函数。
它在每次循环迭代之前检查一个条件,只有在条件满足时才继续执行。
DO WHILE循环的语法如下:```DO WHILE (condition);/* 循环执行的代码 */END;```在这个循环中,condition是一个逻辑表达式,只有在条件为TRUE时才会继续执行循环体中的代码。
例如,下面的代码将重复从1开始加1,直到总和超过100:```DATA test;total = 0;count = 0;DO WHILE (total < 100);count = count + 1;total = total + count;END;PUT count total;RUN;3. DO UNTIL循环:DO UNTIL循环与DO WHILE循环非常相似,只是在判断条件的时候相反。
即只有在条件为FALSE时才继续执行循环体中的代码。
DO UNTIL循环的语法如下:```DO UNTIL (condition);/* 循环执行的代码 */END;```在这个循环中,condition是一个逻辑表达式,只有在条件为FALSE时才会继续执行循环体中的代码。
常用SAS函数简介
152.3 146.7
150.6 148.1
5. 截取函数简介
SAS截取函数应用举例
例5:请把STD=1.92354和CV=0.601106用 3个不同的截取函数(ceil、int、round)进行运 算,并分析这些函数的作用。
q1=2.9199855804 q2=13.894376071
利用HELP查找SAS系统提供的各种函数
Help下拉菜单
SAS 帮助 与文件
索引中键入: SAS Function
SAS函数种类
在SAS系统9.1版本,SAS函数分为二十五种类型, 分别是算术函数、截取函数、数学函数、概率 和密度函数、分位数函数、非中心函数、样本 统计函数、随机数函数、财政金融函数、日期 和时间函数、换算函数和特殊函数等。 在SAS系统6.12版本,SAS函数分为十七种类型 共有178个,SAS系统8.1版本,SAS函数分为二十 二种类型共有319个函数。
例1.2: 以日为单位计算当前日期的天数。
data; x=date (); y=today(); format x y yymmdd10.; put x= y=; run;
例1.3: 将时间值换算为以秒计数的 计算方法。
data; hms=hms (21,50,51); put hms=; x=21*60*60+50*60+51; put x=; mdy=mdy (08,18,2001); put mdy=; format mdy yymmdd10.; run;
练习1
计算以下数据表中日期值所在的年季月以及 处于某月的第几天、某周的第几天。
Date 1991-01-02 1991-01-03 1991-01-04 1991-01-05 1991-01-07 1991-01-08 1991-01-09 1991-01-10 1991-01-11 1991-01-12
2.SAS基础_表达式及函数简介
变量类型转换
字符自动转换为数值(无法转换为数值时,取缺失值)
data; X=1; /*X为数值变量 */ Y=’10’; /*Y为字符变量 */ X=Y; /*将字符变量赋值给一个数值变量时, 自动将字符变量Y转换为数值变量 */ run; data; X=1; /*X为数值变量 */ Y=’10’; /*Y为字符变量 */ Z=X+Y; /*算术表达式中有字符变量时,自动将字符变量Y 转换为数值变量 */ run;
Slide 10
创建变量
使用赋值语句
Data a; x=1; run;/*数据集a中有个变量x,值为1,为数值型*/
使用INPUT语句
Data b; Input x $ y z; Datalines; Aaa 23 45 ; Run; /*创建三个变量,x为字符型,y、z为数值型*/
Slide 11
Slide 25
二 SAS函数的参数
参数类型 • 变量名 • 常数 • 函数
• 表达式 函数及其参数类型举例。
函数举例 Max(X,Y); X=Repeat(‘---‘, 20); Least=Min(sum(of x1-x10),y) ; 参数类型 变量名X,Y 常数 变量名和函数
SAS表达式及函数简介
Slide 1
SAS表达式
SAS表达式是由一系列算符和运算对象形成的一个指令集,它 被执行后产生一个目标值。 运算对象是SAS变量和SAS常数;算符是特殊的运算符、函数 和括号。
表达式分为简单表达式和复合表达式。 下列式子都是表达式。 X+1 3 LOG(X) LOG10(X) P/A*100 1-EXP(N/(N-1)) A=B=C STATE=‘CA’
SAS函数
一、数学函数ABS(x) 求x的绝对值。
MAX(x1,x2,…,xn) 求所有自变量中的最大一个。
MIN(x1,x2,…,xn) 求所有自变量中的最小一个。
MOD(x,y) 求x除以y的余数。
SQRT(x) 求x的平方根。
ROUND(x,eps) 求x按照eps指定的精度四舍五入后的结果,比如ROUND(5654.5654,0.01) 结果为5654.57,ROUND(5654.5654,10)结果为5650。
CEIL(x) 求大于等于x的最小整数。
当x为整数时就是x本身,否则为x右边最近的整数。
FLOOR(x) 求小于等于x的最大整数。
当x为整数时就是x本身,否则为x左边最近的整数。
INT(x) 求x扔掉小数部分后的结果。
FUZZ(x) 当x与其四舍五入整数值相差小于1E-12时取四舍五入。
LOG(x) 求x的自然对数。
LOG10(x) 求x的常用对数。
EXP(x) 指数函数。
SIN(x), COS(x), TAN(x) 求x的正弦、余弦、正切函数。
ARSIN(y) 计算函数y=sin(x)在区间的反函数,y取[-1,1]间值。
ARCOS(y) 计算函数y=cos(x)在的反函数,y取[-1,1]间值。
ATAN(y) 计算函数y=tan(x)在的反函数,y取间值。
SINH(x), COSH(x), TANH(x) 双曲正弦、余弦、正切ERF(x) 误差函数GAMMA(x) 完全函数此外还有符号函数SIGN,函数一阶导数函数DIGAMMA,二阶导数函数TRIGAMMA ,误差函数余函数ERFC,函数自然对数LGAMMA,ORDINAL函数,AIRY 函数,DAIRY函数,Bessel 函数JBESSEL,修正的Bessel函数IBESSEL,等等。
二、数组函数数组函数计算数组的维数、上下界,有利于写出可移植的程序。
数组函数包括:DIM(x) 求数组x第一维的元素的个数(注意当下界为1时元素个数与上界相同,否则元素个数不一定与上界相同)。
常用SAS函数简介
当日期值date=’14JUL2007’d时,试问这一天是
星期几?
精选ppt
18
解答:
data a; Input date YYMMDD10.; Cards; 1991-01-02 1991-01-03 1991-01-04 1991-01-05 1991-01-07 1991-01-08 1991-01-09 1991-01-10 1991-01-11 1991-01-12 ;
在SAS系统6.12版本,SAS函数分为十七种类型 共有178个,SAS系统8.1版本,SAS函数分为二十 二种类型共有319个函数。
精选ppt
11
函数类
例
Arithmetic Character Date and Time Mathematical Noncentrality Quantile
例3:产生一个5×10×2的三维数组,并
提取各维度上元素的个数。
data; array mult{5,10,2} mult1-mult100; a=DIM1(MULT); b=DIM2(MULT); c=DIM3(MULT); put a b c; run;
精选ppt
26
练习 3
产生一个行变量名为2:6,列变量名为4:13 的二维数组,输出各维度上的上界和下界。
22
练习2
ex2.1 计算0、1.57、 3.14对应的正弦函数值, 并将结果显示在输出窗口。
ex2.2 计算e的0次幂,并计算1的自然对数。
精选ppt
23
解答:
Data; a=sin(0); b=sin(1.57); c=sin(3.14); File print; Put a= 6.2 b= 6.2 c= 6.2; Run;
SAS中数据类型转换函数以及自动转换规则
SAS中数据类型转换函数以及自动转换规则在SAS中,数据类型转换函数和自动转换规则帮助我们在不同类型的数据之间进行转换和处理。
下面是关于SAS数据类型转换函数和自动转换规则的详细解释。
1.数据类型转换函数:SAS提供了多种数据类型转换函数,用于将一种数据类型转换为另一种数据类型。
以下是常用的SAS数据类型转换函数:- PUT函数:将数值型变量转换为字符型。
语法为:put(变量名, 格式)。
- INPUT函数:将字符型变量转换为数值型。
语法为:input(变量名, 格式)。
- CATT函数:将多个字符型变量连接成单个字符型变量。
语法为:catt(变量1, 变量2, ...)。
- CATS函数:将多个字符型变量连接成单个字符型变量,并自动去除连接结果中的空格。
语法为:cats(变量1, 变量2, ...)。
- MDY函数:将月、日和年转换为所需的日期格式。
语法为:mdy(月, 日, 年)。
- INTCK函数:计算两个日期之间的时间间隔。
语法为:intck(单位, 开始日期, 结束日期)。
2.自动转换规则:SAS也提供了一些自动转换规则,根据这些规则,SAS可以在需要的时候自动进行数据类型转换。
以下是SAS自动转换规则的一些示例:-将字符型变量与数值型变量进行计算时,SAS会自动将字符型变量转换为数值型变量。
-将数值型变量与字符型变量进行连接时,SAS会自动将数值型变量转换为字符型变量。
-当需要日期类型的数据时,SAS会自动将字符型变量按照日期格式转换为日期型变量。
-当需要字符型变量时,SAS会自动将日期型变量按照日期格式转换为字符型变量。
-当需要逻辑型数据时,SAS会将数值型变量按照一定规则转换为逻辑型数据。
需要注意的是,SAS的自动转换规则有时可能会导致数据的意外改变。
为了避免这种情况,可以使用数据类型转换函数来明确指定需要的数据类型。
总结:在SAS中,数据类型转换函数和自动转换规则是非常重要的。
SAS学习笔记30SAS各种常用随机函数
SAS学习笔记30SAS各种常⽤随机函数
UNIFORM(seed)产⽣(0,1)区域均匀分布随机数,乘同余发⽣器
RANUNI(seed)产⽣(0,1)区域均匀分布随机数,素数模发⽣器
NORMAL(seed)产⽣标准正态分布随机数,利⽤中⼼极限定理近似公式RANNOR(seed)产⽣标准正态分布随机数,利⽤变换抽样法
RANEXP(seed)产⽣λ=1的指数分布随机数
RANGAM(seed, alpha)产⽣伽马分布随机数,alpha>0,seed为任意数值
RANTRI(seed, h)产⽣三⾓分布随机数,0<h<1,seed为任意数值
RANCAU(seed)产⽣标准柯西分布随机数
RANBIN(seed, n, p)产⽣⼆项分布随机数,n>0的整数,0<p<1,seed为任意数值RANPOI(seed, lambda)产⽣泊松分布随机数,lambda>0,seed为任意数值
RANTBL(seed, p1, …, …pn)产⽣离散分布随机数,0≤p i≤1,seed为任意数值。
SAS函数汇总
CALL PRXNEXT Routine
Returns the position and length of a substring that matches a pattern, and iterates over multiple matches within one string. Returns the start position and length for a capture buffer. Returns the position and length of a substring that matches a pattern. Performs a pattern-matching replacement. Searches for a pattern match and returns the position at which the pattern is found. Returns the last bracket match for which there is a match in a pattern. Compiles a Perl regular expression (PRX) that can be used for pattern matching of a character value. Returns a character string that contains the value for a capture buffer. Searches a character string for an alphanumeric character, and returns the first position at which the character is found. Searches a character string for an alphabetic character, and
SAS常用函数参考
SAS常⽤函数参考SAS常⽤函数参考这⼀节分类列出常⽤的函数,需要时可以参看帮助。
基本⼀、数据管理vector:向量 numeric:数值型向量 logical:逻辑型向量character;字符型向量 list:列表 data.frame:数据框c:连接为向量或列表 length:求长度 subset:求⼦集seq,from:to,sequence:等差序列rep:重复 NA:缺失值 NULL:空对象sort,order,unique,rev:排序unlist:展平列表attr,attributes:对象属性mode,typeof:对象存储模式与类型names:对象的名字属性⼆、字符串处理character:字符型向量 nchar:字符数 substr:取⼦串format,formatC:把对象⽤格式转换为字符串paste,strsplit:连接或拆分charmatch,pmatch:字符串匹配grep,sub,gsub:模式匹配与替换三、复数complex,Re,Im,Mod,Arg,Conj:复数函数四、因⼦factor:因⼦ codes:因⼦的编码 levels:因⼦的各⽔平的名字nlevels:因⼦的⽔平个数 cut:把数值型对象分区间转换为因⼦table:交叉频数表 split:按因⼦分组aggregate:计算各数据⼦集的概括统计量tapply:对“不规则”数组应⽤函数数学⼀、计算+, -, *, /, ^, %%, %/%:四则运算ceiling,floor,round,signif,trunc,zapsmall:舍⼊max,min,pmax,pmin:最⼤最⼩值range:最⼤值和最⼩值sum,prod:向量元素和,积cumsum,cumprod,cummax,cummin:累加、累乘sort:排序approx和approx fun:插值diff:差分sign:符号函数⼆、数学函数abs,sqrt:绝对值,平⽅根log, exp, log10, log2:对数与指数函数sin,cos,tan,asin,acos,atan,atan2:三⾓函数sinh,cosh,tanh,asinh,acosh,atanh:双曲函数beta,lbeta,gamma,lgamma,digamma,trigamma,tetragamma,pentagamma,choose ,lchoose:与贝塔函数、伽玛函数、组合数有关的特殊函数fft,mvfft,convolve:富利叶变换及卷积polyroot:多项式求根poly:正交多项式spline,splinefun:样条差值besselI,besselK,besselJ,besselY,gammaCody:Bessel函数deriv:简单表达式的符号微分或算法微分三、数组array:建⽴数组 matrix:⽣成矩阵data.matrix:把数据框转换为数值型矩阵lower.tri:矩阵的下三⾓部分 mat.or.vec:⽣成矩阵或向量t:矩阵转置 cbind:把列合并为矩阵 rbind:把⾏合并为矩阵diag:矩阵对⾓元素向量或⽣成对⾓矩阵aperm:数组转置 nrow, ncol:计算数组的⾏数和列数dim:对象的维向量 dimnames:对象的维名row/colnames:⾏名或列名 %*%:矩阵乘法crossprod:矩阵交叉乘积(内积) outer:数组外积kronecker:数组的Kronecker积 apply:对数组的某些维应⽤函数tapply:对“不规则”数组应⽤函数 sweep:计算数组的概括统计量aggregate:计算数据⼦集的概括统计量 scale:矩阵标准化matplot:对矩阵各列绘图 cor:相关阵或协差阵Contrast:对照矩阵 row:矩阵的⾏下标集col:求列下标集四、线性代数solve:解线性⽅程组或求逆 eigen:矩阵的特征值分解svd:矩阵的奇异值分解 backsolve:解上三⾓或下三⾓⽅程组chol:Choleski分解 qr:矩阵的QR分解chol2inv:由Choleski分解求逆五、逻辑运算<,>,<=,>=,==,!=:⽐较运算符!,&,&&,|,||,xor():逻辑运算符logical:⽣成逻辑向量 all,any:逻辑向量都为真或存在真ifelse():⼆者择⼀ match,%in%:查找unique:找出互不相同的元素 which:找到真值下标集合duplicated:找到重复元素六、优化及求根optimize,uniroot,polyroot:⼀维优化与求根程序设计⼀、控制结构if,else,ifelse,switch:分⽀for,while,repeat,break,next:循环apply,lapply,sapply,tapply,sweep:替代循环的函数。
sas的函数
SAS提供了比一般程序设计语言多几倍的标准函数可以直接用在数据步的计算中,其中包括所有语言都有的数学函数、字符串函数,还包括特有的统计分布函数、分位数函数、随机数函数、日期时间函数、财政金融函数,等等。
这些函数的调用方法类似其它语言,比如求x1,x2,x3三个自变量的和可以用函数SUM(x1,x2,x3) 。
另外,SAS还提供了函数调用的另一种语法以便于把多个数据集变量作为函数自变量,其格式为“函数名(OF 变量名列表)”,其中变量名列表可以是任何合法的变量名列表,比如x1 ,x2,x3的和等价地可以用SUM(OF x1 x2 x3)或SUM(OF x1-x3)表示。
注意两种写法不能混在一起,比如SUM(OF x1,x2,x3)和SUM(x1-x3)都是错的。
本小节对重要的函数加以介绍,其它详见《SAS软件:Base SAS软件使用手册》(高惠璇等编译,中国统计出版社出版)一、数学函数ABS(x) 求x的绝对值。
MAX(x1,x2,…,xn) 求所有自变量中的最大一个。
MIN(x1,x2,…,xn) 求所有自变量中的最小一个。
MOD(x,y) 求x除以y的余数。
SQRT(x) 求x的平方根。
ROUND(x,eps) 求x按照eps指定的精度四舍五入后的结果,比如ROUND(5654.5654,0.01) 结果为5654.57,ROUND(5654.5654,10)结果为5650。
CEIL(x) 求大于等于x的最小整数。
当x为整数时就是x本身,否则为x右边最近的整数。
FLOOR(x) 求小于等于x的最大整数。
当x为整数时就是x本身,否则为x左边最近的整数。
INT(x) 求x扔掉小数部分后的结果。
FUZZ(x) 当x与其四舍五入整数值相差小于1E-12时取四舍五入。
LOG(x) 求x的自然对数。
LOG10(x) 求x的常用对数。
EXP(x) 指数函数。
SIN(x), COS(x), TAN(x) 求x的正弦、余弦、正切函数。
SAS学习系列06. 使用SAS函数
06. 使用SAS函数(一)创建并定义新变量可以在数据步中,利用赋值语句创建或重新定义新变量(列),语法:变量名=表达式;注:(1)表达式可以是数值或字符常量、数学表达式、函数等;(2)加减乘除幂:+ - * / **,也可以使用括号。
例1下面数据(C:\MyRawData\Garden.dat)是番茄、南瓜、豌豆、葡萄的重量:代码:data homegarden;infile'c:\MyRawData\Garden.dat';input Name $ 1-7 Tomato Zucchini Peas Grapes;Zone = 14;Type = 'home';Zucchini = Zucchini * 10;Total = Tomato + Zucchini + Peas + Grapes;PerTom = (Tomato / Total) * 100;run;proc print data = homegarden;title'Home Gardening Survey';run;运行结果:程序说明:(1)5-8行使用了5个赋值语句,第6行改写旧变量,运行结果将输出所有变量;(2)若观测值中有缺省值,相应的新变量也出现缺省值。
(二)使用SAS函数一、SAS函数概述SAS自带数百个函数,主要包括以下函数类:字符/字符串函数日期/时间函数距离/州/邮编代码函数数学函数概率/描述统计/随机数函数金融函数宏函数变量信息函数函数基本调用形式(可以嵌套调用):函数名(参数1,参数2,…);例2南瓜雕刻比赛的数据(C:\MyRawData\pumpkin.dat)包含了参赛者的名字、年龄、雕刻的南瓜类型、报名日期、五位裁判给出的分数:代码:data contest;infile'c:\MyRawData\Pumpkin.dat';input Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10.(Scr1 Scr2 Scr3 Scr4 Scr5) (4.1);AvgScore = mean(Scr1, Scr2, Scr3, Scr4, Scr5);DayEntered = day(Date);Type = upcase(Type); /* 转化为大写 */run;proc print data = contest;title'Pumpkin Carving Contest';run;运行结果:程序说明:(1)均值函数mean( )返回非缺省值参数的平均值;(2)d ay( )函数返回日期值距离1961年1月1日的天数。
SAS函数大全
SAS函数大全SAS FUNCTIONSExcerpted from SAS release 8.2 Online DocumentationJuly, 2004Arithmetic FunctionsABS(argument)returns absolute valueDIM(array-name)returns the number of elements in a one-dimensional array or the numberof elements in a specified dimension of a multidimensional array.n specifies the dimension, in a multidimensional array, forwhich you want to know the the number of elements.DIM(array-name,bound-n)returns the number of elements in a one-dimensional array or the numberof elements in the specified dimension of a multidimensional arraybound-n specifies the dimension in a multidimensional array, for which you want to know the number of elements. HBOUND(array-name)returns the upper bound of an array HBOUND(array-name,bound-n)returns the upper bound of an arrayLBOUND(array-name)returns the lower bound of an arrayLBOUND(array-name,bound-n)returns the lower bound of an arrayMAX(argument,argument, ...)returns the largest value of the numeric argumentsMIN(argument,argument, ...)returns the smallest value of the numeric argumentsMOD(argument-1, argument-2)returns the remainderSIGN(argument)returns the sign of a value or 0SQRT(argument)returns the square rootCharacter FunctionsBYTE(n)returns one character in the ASCII or EBCDICcollating sequence where n is an integer representinga specific ASCII or EBCDIC characterCOLLATE(start-position<,end-position>) | (start-position<,,length>)returns an ASCII or EBCDIC collating sequence character stringCOMPBL(source)removes multiple blanks between words in acharacter stringCOMPRESS(source<,characters-to-remove>)removes specific characters from a character string DEQUOTE(argument)removes quotation marks from a character value INDEX(source,excerpt)searches the source for the character string specifiedby the excerptINDEXC(source,excerpt-1<, ... excerpt-n>)searches the source for any character present in theexcerptINDEXW(source,excerpt)searches the source for a specified pattern as a word LEFT(argument)left-aligns a SAS character stringLENGTH(argument)returns the length of an argumentLOWCASE(argument)converts all letters in an argument to lowercase QUOTE(argument)adds double quotation marks to a character value RANK(x)returns the position of a character in the ASCII orEBCDIC collating sequenceREPEAT(argument,n)repeats a character expressionREVERSE(argument)reverses a character expressionRIGHT(argument)right-aligns a character expressionSCA N(argument,n<,delimiters>)returns a given word from a character expression SOUNDEX(argument)encodes a string to facilitate searchingreplaces character value contentsSUBSTR(argument,position<,n>)=characters-to-replacevar=SUBSTR(argument,position<,n>)extracts a substring from an argument. (var is anyvalid SAS variable name.)TRANSLATE(source,to-1,from-1<,...to-n,from-n>)replaces specific characters in a characterexpressionTRANW RD(source,target,replacement)replaces or removes all occurrences of a word in acharacter stringTRIM(argument)removes trailing blanks from character expressionand returns one blank if the expression is missing TRIMN(argument)removes trailing blanks from character expressionsand returns a null string if the expression is missingUPCASE(argument)converts all letters in an argument to uppercase VERIFY(source,excerpt-1<,...excerpt-n)returns the position of the first character unique toan expressionDate and Time FunctionsDATDIF(sdate,edate,basis)returns the number of days between two datesDATE()returns the current date as a SAS date valueDATEJUL(julian-date)converts a Julian date to a SAS date valueDATEPA RT(datetime)extracts the date from a SAS datetime value DATETIME()returns the current date and time of day DA Y(date)returns the day of the month from a SAS date value DHMS(date,hour,minute,second)returns a SAS datetime value from date, hour, minute, andsecondHMS(hour,minute,second)returns a SAS time value from hour, minute, and second HOUR()returns the hour from a SAS time or datetime value INTCK('interval',from,to)returns the number of time intervals in a given time spanINTNX('interval',start-from,increment<,'alignment'>)advances a date, time, or datetime value by a given interval, and returns a date, time, or datetime valueJULDATE(date)returns the Julian date from a SAS date value MDY(month,day,year)returns a SAS date value from month, day, and year values MINUTE(time | datetime)returns the minute from a SAS time or datetime value MONTH(date)returns the month from a SAS date valueQTR(date)returns the quarter of the year from a SAS datevalue SECOND(time | datetime)returns the second from a SAS time or datetime value TIME()returns the current time of day TIMEPA RT(datetime)extracts a time value from a SAS datetime valueTODA Y()returns the current date as a SAS date valueWEEKDA Y(date)returns the day of the week from a SAS date valueYEA R(date)returns the year from a SAS date valueYRDIF(sdate,edate,basis)returns the difference in years between two datesYYQ(year,quarter)returns a SAS date value from the year and quarterMathematical FunctionsAIRY(x)returns the value of the AIRY functionDAIRY(x)returns the derivative of the AIRY functionDIGAMMA(argument)returns the value of the DIGAMMA functionERF(argument)returns the value of the (normal) error functionERFC(argument)returns the value of the (normal) error functionEXP(argument)returns the value of the exponential function GAMMA(argument)returns the value of the GAMMA functionIBESSEL(nu,x,kode)returns the value of the modified bessel functionJBESSEL(nu,x)returns the value of the bessel functionLGAMMA(argument)returns the natural logarithm of the GAMMA functionLOG(argument)returns the natural (base e) logarithmLOG2(argument)returns the logarithm to the base 2LOG10(argument)returns the logarithm to the base 10TRIGAMMA(argument)returns the value of the TRIGAMMA functionNoncentrality FunctionsCNONCT(x,df,prob)returns the noncentrality parameter from a chi-squared distributionFNONCT(x,ndf,ddf,prob)returns the value of the noncentrality parameter of an F distributionTNONCT(x,df,prob)returns the value of the noncentrality parameter from the student's t distribution Probability and Density FunctionsCDF('dist',quantile,parm-1,...,parm-k)computes cumulative distribution functionsLOGPDF|LOGPMF('dist',quantile,parm-1,...,parm-k)computes the logarithm of a probability density (mass) function. The two functions are identical.LOGSDF('dist',quantile,parm-1,...,parm-k) computes the logarithm of a survival functionPDF|PMF('dist',quantile,parm-1,...,parm-k)computes probability density (mass) functions POISSON(m,n)returns the probability from a POISSON distribution PROBBETA(x,a,b)returns the probability from a beta distribution PROBBNML(p,n,m)returns the probability from a binomial distribution PROBCHI(x,df<,nc>)returns the probability from a chi-squared distribution PROBF(x,ndf,ddf<,nc>)returns the probability from an F distribution PROBGAM(x,a)returns the probability from a gamma distribution PROBHYPR(N,K,n,x<,r>)returns the probability from a hypergeometric distribution PROBMC probabilities and criticalvalues (quantiles) from variousdistributions for multiple comparisons of the means ofseveral groups.PROBNEGB(p,n,m)returns the probability from a negative binomialdistributionPROBBNRM(x,y,r)standardized bivariate normal distribution PROBNORM(x)returns the probability from the standard normal distributionPROBT(x,df<,nc>)returns the probability from a Student's t distribution SDF('dist',quantile,parm-1,...,parm-k) computes a survival functionQuantile FunctionsBETAINV(p,a,b)returns a quantile from the beta distribution CINV(p,df<,nc>)returns a quantile from the chi-squared distributionFINV(p,ndf,ddf<,nc>)returns a quantile from the F distributionGAMINV(p,a)returns a quantile from the gamma distribution PROBIT(p)returns a quantile from the standard normal distributionTINV(p,df<,nc>)returns a quantile from the t distributionSample Statistics FunctionsCSS(argument,argument,...)returns the corrected sum of squares CV(argument,argument,...)returns the coefficient of variation KURTOSIS(argument,argument,...)returns the kurtosis (or 4th moment) MAX(argument,argument, ...)returns the largest valueMIN(argument,argument, ...)returns the smallest valueMEAN(argument,argument, ...)returns the arithmetic mean(average)MISSING(numeric-expression | character-expression)returns a numeric result that indicates whether the argument contains a missing valueN(argument,argument, ....)returns the number of nonmissing values NMISS(argument,argument, ...)returns the number of missing values ORDINA L(count,argument,argument,...)returns the largest value of a part of a list RANGE(argument,argument,...)returns the range of values SKEWNESS(argument,argument,argument,...)returns the skewnessSTD(argument,argument,...)returns the standard deviation STDERR(argument,argument,...)returns the standard error of the mean SUM(argument,argument,...)returns the sumUSS(argument,argument,...)returns the uncorrected sum of squares VA R(argument,argument,...)returns the variance State and ZIP Code FunctionsFIPNAME(expression)converts FIPS codes to uppercase state namesFIPNAMEL(expression)converts FIPS codes to mixed case state namesFIPSTATE(expression)converts FIPS codes to two-character postal codesSTFIPS(postal-code)converts state postal codes to FIPS state codesSTNAME(postal-code)converts state postal codes to uppercase state namesTip:For Version 6, the maximum length of the value that isreturned is 200 characters. For Version 7 and beyond, themaximum length is 20 characters.STNAMEL(postal-code)converts state postal codes to mixed case state namesTip:For Version 6, the maximum length of the value that isreturned is 200 characters. For Version 7 and beyond, themaximum length is 20 characters.ZIPFIPS(zip-code)converts ZIP codes to FIPS state codesZIPNAME(zip-code)converts ZIP codes to uppercase state namesZIPNAMEL(zip-code)converts ZIP codes to mixed case state namesZIPSTATE(zip-code)converts ZIP codes to state postal codes Trigonometric and Hyperbolic Functions ARCOS(argument)returns the arccosineARSIN(argument)returns the arcsineATAN(argument)returns the arctangentCOS(argument)returns the cosineCOSH(argument)returns the hyperbolic cosineSIN(argument)returns the sineSINH(argument)returns the hyperbolic sineTAN(argument)returns the tangentTANH(argument)returns the hyperbolic tangentTruncation FunctionsCEIL(argument)returns the smallest integer that is greater than or equal to theargumentFLOOR(argument)returns the largest integer that is less than or equal to the argument FUZZ(argument)returns the nearest integer if the argument is within 1E-12INT(argument)returns the integer valueROUND(argument,round-off-unit)rounds to the nearestround-off unitTRUNC(number, length)truncates a numeric value to a specified lengthVariable Information FunctionsGETVA RC(data-set-id,var-num)returns the value of a SAS data set character variableGETVA RN(data-set-id,var-num)returns the value of a SAS data set numeric variableVA RFMT(data-set-id,var-num)returns the format assigned to a SAS data set variableVA RINFMT(data-set-id,var-returns the informat assigned to a SAS data set variablenum)returns the label assigned to a SAS data set variableVA RLA BEL(data-set-id,var-num)VA RLEN(data-set-id,var-num)returns the length of a SAS data set variablereturns the name of a SAS data set variableVA RNAME(data-set-id,var-num)VA RNUM(data-set-id,var-name)returns the number of a SAS data set variable's position in a SAS datasetVA RRA Y(name)returns a value that indicates whether the specified name is an array VA RRA YX(expression)returns a value that indicates whether the value of the specifiedargument is an arrayVA RTYPE(data-set-id,var-num)returns the data type of a SAS data set variableVFORMAT(var)returns the format associated with the given variableVFORMATD(var)returns the format decimal value associated with the given variable VFORMATDX(expression)returns the format decimal value associated with the value of the specified argumentVFORMATN(var)returns the format name associated with the given variable VFORMATNX(expression)returns the format name associated with the value of the specifiedargumentVFORMATW(var)returns the format width associated with the given variable VFORMATWX(expression)returns the format width associated with the value of the specifiedargumentVFORMATX(expression)returns the format associated with the value of the specified argument VINARRA Y(var)returns a value that indicates whether the given variable is a member of an arrayVINARRA YX(expression)returns a value that indicates whether the value of the specifiedargument is a member of an arrayVINFORMAT(var)returns the informat associated with the given variable VINFORMATD(var)returns the informat decimal value associated with the given variable VINFORMATDX(expression)returns the informat decimal value associated with the value of thespecified argumentVINFORMATN(var)returns the informat name associated with the given variableVINFORMATNX(expression)returns the informat nameassociated with the value of the specifiedargumentVINFORMATW(var)returns the informat width associated with the given variable VINFORMATWX(expression)returns the informat width associated with the value of the specified argumentVINFORMATX(expression)returns the informat associated with the value of the specified argument VLA BEL(var)returns the label associated with the given variableVLA BELX(expression)returns the variable label for the value of a specified argument VLENGTH(var)returns the compile-time (allocated) size of the given variable VLENGTHX(expression)returns the compile-time (allocated) size for the value of the specifiedargumentVNAME(var)returns the name of the given variableVNAMEX(expression)validates the value of the specified argument as a variable name VTYPE(var)returns the type (character or numeric) of the given variableVTYPEX(expression)returns the type (character or numeric) for the value of the specifiedargument。
SAS函数大全
SAS FUNCTIONSExcerpted from SAS release 8.2 Online DocumentationJuly, 2004Arithmetic FunctionsABS(argument)returns absolute valueDIM<n>(array-name)returns the number of elements in a one-dimensional array or the numberof elements in a specified dimension of a multidimensional array.n specifies the dimension, in a multidimensional array, forwhich you want to know the the number of elements.DIM(array-name,bound-n)returns the number of elements in a one-dimensional array or the numberof elements in the specified dimension of a multidimensional arraybound-n specifies the dimension in a multidimensional array,for which you want to know the number of elements. HBOUND<n>(array-name)returns the upper bound of an arrayHBOUND(array-name,bound-n)returns the upper bound of an arrayLBOUND<n>(array-name)returns the lower bound of an arrayLBOUND(array-name,bound-n)returns the lower bound of an arrayMAX(argument,argument, ...)returns the largest value of the numeric argumentsMIN(argument,argument, ...)returns the smallest value of the numeric argumentsMOD(argument-1, argument-2)returns the remainderSIGN(argument)returns the sign of a value or 0SQRT(argument)returns the square rootCharacter FunctionsBYTE(n)returns one character in the ASCII or EBCDICcollating sequence where n is an integer representinga specific ASCII or EBCDIC characterCOLLATE(start-position<,end-position>) | (start-position<,,length>)returns an ASCII or EBCDIC collating sequence character stringCOMPBL(source)removes multiple blanks between words in acharacter stringCOMPRESS(source<,characters-to-remove>)removes specific characters from a character string DEQUOTE(argument)removes quotation marks from a character value INDEX(source,excerpt)searches the source for the character string specifiedby the excerptINDEXC(source,excerpt-1<, ... excerpt-n>)searches the source for any character present in theexcerptINDEXW(source,excerpt)searches the source for a specified pattern as a word LEFT(argument)left-aligns a SAS character stringLENGTH(argument)returns the length of an argumentLOWCASE(argument)converts all letters in an argument to lowercase QUOTE(argument)adds double quotation marks to a character value RANK(x)returns the position of a character in the ASCII orEBCDIC collating sequenceREPEAT(argument,n)repeats a character expressionREVERSE(argument)reverses a character expressionRIGHT(argument)right-aligns a character expressionSCA N(argument,n<,delimiters>)returns a given word from a character expression SOUNDEX(argument)encodes a string to facilitate searchingreplaces character value contentsSUBSTR(argument,position<,n>)=characters-to-replacevar=SUBSTR(argument,position<,n>)extracts a substring from an argument. (var is anyvalid SAS variable name.)TRANSLATE(source,to-1,from-1<,...to-n,from-n>)replaces specific characters in a characterexpressionTRANW RD(source,target,replacement)replaces or removes all occurrences of a word in acharacter stringTRIM(argument)removes trailing blanks from character expressionand returns one blank if the expression is missing TRIMN(argument)removes trailing blanks from character expressionsand returns a null string if the expression is missing UPCASE(argument)converts all letters in an argument to uppercase VERIFY(source,excerpt-1<,...excerpt-n)returns the position of the first character unique toan expressionDate and Time FunctionsDATDIF(sdate,edate,basis)returns the number of days between two datesDATE()returns the current date as a SAS date valueDATEJUL(julian-date)converts a Julian date to a SAS date valueDATEPA RT(datetime)extracts the date from a SAS datetime value DATETIME()returns the current date and time of dayDA Y(date)returns the day of the month from a SAS date value DHMS(date,hour,minute,second)returns a SAS datetime value from date, hour, minute, andsecondHMS(hour,minute,second)returns a SAS time value from hour, minute, and second HOUR(<time | datetime>)returns the hour from a SAS time or datetime value INTCK('interval',from,to)returns the number of time intervals in a given time spanINTNX('interval',start-from,increment<,'alignment'>)advances a date, time, or datetime value by a given interval, and returns a date, time, or datetime valueJULDATE(date)returns the Julian date from a SAS date valueMDY(month,day,year)returns a SAS date value from month, day, and year values MINUTE(time | datetime)returns the minute from a SAS time or datetime value MONTH(date)returns the month from a SAS date valueQTR(date)returns the quarter of the year from a SAS date value SECOND(time | datetime)returns the second from a SAS time or datetime value TIME()returns the current time of dayTIMEPA RT(datetime)extracts a time value from a SAS datetime valueTODA Y()returns the current date as a SAS date valueWEEKDA Y(date)returns the day of the week from a SAS date valueYEA R(date)returns the year from a SAS date valueYRDIF(sdate,edate,basis)returns the difference in years between two datesYYQ(year,quarter)returns a SAS date value from the year and quarterMathematical FunctionsAIRY(x)returns the value of the AIRY functionDAIRY(x)returns the derivative of the AIRY functionDIGAMMA(argument)returns the value of the DIGAMMA functionERF(argument)returns the value of the (normal) error functionERFC(argument)returns the value of the (normal) error functionEXP(argument)returns the value of the exponential functionGAMMA(argument)returns the value of the GAMMA functionIBESSEL(nu,x,kode)returns the value of the modified bessel functionJBESSEL(nu,x)returns the value of the bessel functionLGAMMA(argument)returns the natural logarithm of the GAMMA functionLOG(argument)returns the natural (base e) logarithmLOG2(argument)returns the logarithm to the base 2LOG10(argument)returns the logarithm to the base 10TRIGAMMA(argument)returns the value of the TRIGAMMA functionNoncentrality FunctionsCNONCT(x,df,prob)returns the noncentrality parameter from a chi-squared distributionFNONCT(x,ndf,ddf,prob)returns the value of the noncentrality parameter of an F distributionTNONCT(x,df,prob)returns the value of the noncentrality parameter from the student's t distribution Probability and Density FunctionsCDF('dist',quantile,parm-1,...,parm-k)computes cumulative distribution functionsLOGPDF|LOGPMF('dist',quantile,parm-1,...,parm-k)computes the logarithm of a probability density (mass) function. The two functions are identical.LOGSDF('dist',quantile,parm-1,...,parm-k) computes the logarithm of a survival functionPDF|PMF('dist',quantile,parm-1,...,parm-k)computes probability density (mass) functions POISSON(m,n)returns the probability from a POISSON distribution PROBBETA(x,a,b)returns the probability from a beta distribution PROBBNML(p,n,m)returns the probability from a binomial distribution PROBCHI(x,df<,nc>)returns the probability from a chi-squared distribution PROBF(x,ndf,ddf<,nc>)returns the probability from an F distribution PROBGAM(x,a)returns the probability from a gamma distribution PROBHYPR(N,K,n,x<,r>)returns the probability from a hypergeometric distribution PROBMC probabilities and critical values (quantiles) from variousdistributions for multiple comparisons of the means ofseveral groups.PROBNEGB(p,n,m)returns the probability from a negative binomialdistributionPROBBNRM(x,y,r)standardized bivariate normal distribution PROBNORM(x)returns the probability from the standard normaldistributionPROBT(x,df<,nc>)returns the probability from a Student's t distribution SDF('dist',quantile,parm-1,...,parm-k) computes a survival functionQuantile FunctionsBETAINV(p,a,b)returns a quantile from the beta distributionCINV(p,df<,nc>)returns a quantile from the chi-squared distributionFINV(p,ndf,ddf<,nc>)returns a quantile from the F distributionGAMINV(p,a)returns a quantile from the gamma distributionPROBIT(p)returns a quantile from the standard normal distributionTINV(p,df<,nc>)returns a quantile from the t distributionSample Statistics FunctionsCSS(argument,argument,...)returns the corrected sum of squares CV(argument,argument,...)returns the coefficient of variation KURTOSIS(argument,argument,...)returns the kurtosis (or 4th moment) MAX(argument,argument, ...)returns the largest valueMIN(argument,argument, ...)returns the smallest valueMEAN(argument,argument, ...)returns the arithmetic mean (average)MISSING(numeric-expression | character-expression)returns a numeric result that indicates whether the argument contains a missing valueN(argument,argument, ....)returns the number of nonmissing values NMISS(argument,argument, ...)returns the number of missing values ORDINA L(count,argument,argument,...)returns the largest value of a part of a list RANGE(argument,argument,...)returns the range of values SKEWNESS(argument,argument,argument,...)returns the skewnessSTD(argument,argument,...)returns the standard deviation STDERR(argument,argument,...)returns the standard error of the mean SUM(argument,argument,...)returns the sumUSS(argument,argument,...)returns the uncorrected sum of squares VA R(argument,argument,...)returns the varianceState and ZIP Code FunctionsFIPNAME(expression)converts FIPS codes to uppercase state namesFIPNAMEL(expression)converts FIPS codes to mixed case state namesFIPSTATE(expression)converts FIPS codes to two-character postal codesSTFIPS(postal-code)converts state postal codes to FIPS state codesSTNAME(postal-code)converts state postal codes to uppercase state namesTip:For Version 6, the maximum length of the value that isreturned is 200 characters. For Version 7 and beyond, themaximum length is 20 characters.STNAMEL(postal-code)converts state postal codes to mixed case state namesTip:For Version 6, the maximum length of the value that isreturned is 200 characters. For Version 7 and beyond, themaximum length is 20 characters.ZIPFIPS(zip-code)converts ZIP codes to FIPS state codesZIPNAME(zip-code)converts ZIP codes to uppercase state namesZIPNAMEL(zip-code)converts ZIP codes to mixed case state namesZIPSTATE(zip-code)converts ZIP codes to state postal codesTrigonometric and Hyperbolic Functions ARCOS(argument)returns the arccosineARSIN(argument)returns the arcsineATAN(argument)returns the arctangentCOS(argument)returns the cosineCOSH(argument)returns the hyperbolic cosineSIN(argument)returns the sineSINH(argument)returns the hyperbolic sineTAN(argument)returns the tangentTANH(argument)returns the hyperbolic tangentTruncation FunctionsCEIL(argument)returns the smallest integer that is greater than or equal to theargumentFLOOR(argument)returns the largest integer that is less than or equal to the argument FUZZ(argument)returns the nearest integer if the argument is within 1E-12INT(argument)returns the integer valueROUND(argument,round-off-unit)rounds to the nearest round-off unitTRUNC(number, length)truncates a numeric value to a specified lengthVariable Information FunctionsGETVA RC(data-set-id,var-num)returns the value of a SAS data set character variableGETVA RN(data-set-id,var-num)returns the value of a SAS data set numeric variableVA RFMT(data-set-id,var-num)returns the format assigned to a SAS data set variableVA RINFMT(data-set-id,var-returns the informat assigned to a SAS data set variablenum)returns the label assigned to a SAS data set variableVA RLA BEL(data-set-id,var-num)VA RLEN(data-set-id,var-num)returns the length of a SAS data set variablereturns the name of a SAS data set variableVA RNAME(data-set-id,var-num)VA RNUM(data-set-id,var-name)returns the number of a SAS data set variable's position in a SAS datasetVA RRA Y(name)returns a value that indicates whether the specified name is an array VA RRA YX(expression)returns a value that indicates whether the value of the specifiedargument is an arrayVA RTYPE(data-set-id,var-num)returns the data type of a SAS data set variableVFORMAT(var)returns the format associated with the given variableVFORMATD(var)returns the format decimal value associated with the given variable VFORMATDX(expression)returns the format decimal value associated with the value of thespecified argumentVFORMATN(var)returns the format name associated with the given variable VFORMATNX(expression)returns the format name associated with the value of the specifiedargumentVFORMATW(var)returns the format width associated with the given variable VFORMATWX(expression)returns the format width associated with the value of the specifiedargumentVFORMATX(expression)returns the format associated with the value of the specified argument VINARRA Y(var)returns a value that indicates whether the given variable is a member ofan arrayVINARRA YX(expression)returns a value that indicates whether the value of the specifiedargument is a member of an arrayVINFORMAT(var)returns the informat associated with the given variable VINFORMATD(var)returns the informat decimal value associated with the given variable VINFORMATDX(expression)returns the informat decimal value associated with the value of thespecified argumentVINFORMATN(var)returns the informat name associated with the given variableVINFORMATNX(expression)returns the informat name associated with the value of the specifiedargumentVINFORMATW(var)returns the informat width associated with the given variable VINFORMATWX(expression)returns the informat width associated with the value of the specifiedargumentVINFORMATX(expression)returns the informat associated with the value of the specified argument VLA BEL(var)returns the label associated with the given variableVLA BELX(expression)returns the variable label for the value of a specified argument VLENGTH(var)returns the compile-time (allocated) size of the given variable VLENGTHX(expression)returns the compile-time (allocated) size for the value of the specifiedargumentVNAME(var)returns the name of the given variableVNAMEX(expression)validates the value of the specified argument as a variable name VTYPE(var)returns the type (character or numeric) of the given variableVTYPEX(expression)returns the type (character or numeric) for the value of the specifiedargument。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SAS 常用函数汇总一、数学函数ABS(x) 求x的绝对值。
MAX(x1,x2,…,xn) 求所有自变量中的最大一个。
MIN(x1,x2,…,xn) 求所有自变量中的最小一个。
MOD(x,y) 求x除以y的余数。
SQRT(x) 求x的平方根。
ROUND(x,eps) 求x按照eps指定的精度四舍五入后的结果,比如ROUND(5654.5654,0.01) 结果为5654.57,ROUND(5654.5654,10)结果为5650。
CEIL(x) 求大于等于x的最小整数。
当x为整数时就是x本身,否则为x右边最近的整数。
FLOOR(x) 求小于等于x的最大整数。
当x为整数时就是x本身,否则为x左边最近的整数。
INT(x) 求x扔掉小数部分后的结果。
FUZZ(x) 当x与其四舍五入整数值相差小于1E-12时取四舍五入。
LOG(x) 求x的自然对数。
LOG10(x) 求x的常用对数。
EXP(x) 指数函数。
SIN(x), COS(x), TAN(x) 求x的正弦、余弦、正切函数。
ARSIN(y) 计算函数y=sin(x)在区间的反函数,y取[-1,1]间值。
ARCOS(y) 计算函数y=cos(x)在的反函数,y取[-1,1]间值。
ATAN(y) 计算函数y=tan(x)在的反函数,y取间值。
SINH(x), COSH(x), TANH(x) 双曲正弦、余弦、正切ERF(x) 误差函数GAMMA(x) 完全函数此外还有符号函数SIGN,函数一阶导数函数DIGAMMA,二阶导数函数TRIGAMMA ,误差函数余函数ERFC,函数自然对数LGAMMA,ORDINAL函数,AIRY 函数,DAIRY函数,Bessel函数JBESSEL,修正的Bessel函数IBESSEL,等等。
二、数组函数数组函数计算数组的维数、上下界,有利于写出可移植的程序。
数组函数包括:DIM(x) 求数组x第一维的元素的个数(注意当下界为1时元素个数与上界相同,否则元素个数不一定与上界相同)。
DIM k(x) 求数组x第k维的元素的个数。
LBOUND(x) 求数组x第一维的下界。
HBOUND(x) 求数组x第一维的上界。
LBOUND k(x) 求数组x第 k维的下界。
HBOUND k(x) 求数组x第 k维的上界。
三、字符函数较重要的字符函数有:TRIM(s) 返回去掉字符串s的尾随空格的结果。
UPCASE(s) 把字符串s中所有小写字母转换为大写字母后的结果。
LOWCASE(s) 把字符串s中所有大写字母转换为小写字母后的结果。
INDEX(s,s1) 查找s1在s中出现的位置。
找不到时返回0。
RANK(s) 字符s的ASCII码值。
BYTE(n) 第n个ASCII码值的对应字符。
REPEAT(s,n) 字符表达式s重复n次。
SUBSTR(s,p,n) 从字符串s中的第p个字符开始抽取n个字符长的子串TRANWRD(s,s1,s2) 从字符串s中把所有字符串s1替换成字符串s2后的结果。
其它字符函数还有COLLATE,COMPRESS,INDEXC,LEFT,LENGTH,REVERSE,RIGHT,SCAN ,TRANSLATE,VERIFY,COMPBL,DEQUOTE,INDEXW,QUOTE,SOUNDEX,TRIMN,INDEXW。
四、日期和时间函数常用日期和时间函数有:MDY(m,d,yr) 生成yr年m月d日的SAS日期值YEAR(date) 由SAS日期值date得到年MONTH(date) 由SAS日期值date得到月DAY(date) 由SAS日期值date得到日WEEKDAY(date) 由SAS日期值date得到星期几QTR(date) 由SAS日期值date得到季度值HMS(h,m,s) 由小时h、分钟m、秒s生成SAS时间值DHMS(d,h,m,s) 由SAS日期值d、小时h、分钟m、秒s生成SAS日期时间值DATEPART(dt) 求SAS日期时间值dt的日期部分INTNX(interval,from,n) 计算从from开始经过n个in间隔后的SAS日期。
其中interval 可以取'YEAR'、'QTR'、'MONTH'、'WEEK'、'DAY'等。
比如,INTNX('MONTH', '16Dec1997'd, 3)结果为1998年3月1日。
注意它总是返回一个周期的开始值。
INTCK(interval,from,to) 计算从日期from到日期to中间经过的interval间隔的个数,其中interval取'MONTH'等。
比如,INTCK('YEAR', '31Dec1996'd, '1Jan1998'd)计算1996年12 月31日到1998年1月1日经过的年间隔的个数,结果得2,尽管这两个日期之间实际只隔1年。
其它日期和时间函数还有DATE、TODAY、DATETIME、DATEJUL、JULDATE、HOUR、MINUTE、SECOND 、TIME、TIMEPART等。
详见《SAS系统-Base SAS软件使用手册》、《SAS系统-SAS/ETS软件使用手册》。
五、分布密度函数、分布函数作为一个统计计算语言,SAS提供了多种概率分布的有关函数。
分布密度、概率、累积分布函数等可以通过几种统一的格式调用,格式为分布函数值 = CDF(' 分布', x <, 参数表>);密度值 = PDF(' 分布', x <, 参数表>);概率值 = PMF(' 分布', x <, 参数表>);对数密度值 = LOGPDF(' 分布', x <, 参数表>);对数概率值 = LOGPMF(' 分布', x <, 参数表>);CDF计算由'分布'指定的分布的分布函数, PDF计算分布密度函数值,PMF计算离散分布的分布概率,LOGPDF为PDF的自然对数,LOGPMF为PMF的自然对数。
函数在自变量 x处计算,<, 参数表>表示可选的参数表。
分布类型取值可以为: BERNOULLI, BETA, BINOMIAL, CAUCHY, CHISQUARED, EXPONENTIAL, F, GAMMA, GEOMETRIC, HYPERGEOMETRIC, LAPLACE, LOGISTIC, LOGNORMAL, NEGBINOMIAL, NORMAL 或 GAUSSIAN, PARETO, POISSON, T, UNIFORM, WALD 或 IGAUSS, and WEIBULL。
可以只写前四个字母。
例如,PDF('NORMAL', 1.96)计算标准正态分布在1.96处的密度值(0.05844),CDF('NORMAL', 1.96)计算标准正态分布在1.96处的分布函数值(0.975)。
PMF对连续型分布即PDF。
除了用上述统一的格式调用外,SAS还单独提供了常用的分布的密度、分布函数。
PROBNORM(x) 标准正态分布函数PROBT(x,df<,nc>) 自由度为df的t分布函数。
可选参数nc为非中心参数。
PROBCHI(x,df<,nc>) 自由度为df的卡方分布函数。
可选参数nc为非中心参数。
PROBF(x,ndf,ddf<,nc>) F(ndf,ddf)分布的分布函数。
可选参数nc为非中心参数。
PROBBNML(p,n,m) 设随机变量Y服从二项分布B(n,p),此函数计算P(Y m)。
POISSON((lambda,n) 参数为lambda的Poisson分布Y n的概率。
PROBNEGB(p,n,m) 参数为(n,p)的负二项分布Y m的概率。
PROBHYPR(N,K,n,x<,r>) 超几何分布的分布函数。
设N个产品中有K个不合格品,抽取n个样品,其中不合格品数小于等于x的概率为此函数值。
可选参数r是不匀率,缺省为1 ,r代表抽到不合格品的概率是抽到合格品概率的多少倍。
PROBBETA(x,a,b) 参数为(a,b)的Beta分布的分布函数。
PROBGAM(x,a) 参数为a的Gamma分布的分布函数。
PROBMC 计算多组均值的多重比较检验的概率值和临界值。
PROBBNRM(x,y,r) 标准二元正态分布的分布函数,r为相关系数。
六、分位数函数分位数函数是概率分布函数的反函数。
其自变量在0到1之间取值。
分位数函数计算的是分布的左侧分位数。
SAS提供了六种常见连续型分布的分位数函数。
PROBIT(p) 标准正态分布左侧p分位数。
结果在-5到5之间。
TINV(p, df <,nc>) 自由度为df的t分布的左侧p分位数。
可选参数nc为非中心参数。
CINV(p,df<,nc>) 自由度为df的卡方分布的左侧p分位数。
可选参数nc为非中心参数。
FINV(p,ndf,ddf<,nc>) F(ndf,ddf)分布的左侧p分位数。
可选参数nc为非中心参数。
GAMINV(p,a) 参数为a的伽马分布的左侧p分位数。
BETAINV(p,a,b) 参数为(a,b)的贝塔分布的左侧p分位数。
七、随机数函数SAS可以用来进行随机模拟。
它提供了常见分布的伪随机数生成函数。
1.均匀分布随机数有两个均匀分布随机数函数:UNIFORM(seed),seed必须是常数,为0,或5位、6位、7位的奇数。
RANUNI(seed),seed为小于2**31-1的任意常数。
在同一个数据步中对同一个随机数函数的多次调用将得到不同的结果,但不同数据步中从同一种子出发将得到相同的随机数序列。
随机数种子如果取0或者负数则种子采用系统日期时间。
2.正态分布随机数有两种,NORMAL(seed),seed为0,或5位、6位、7位的奇数。
RANNOR(seed),seed为任意数值常数。
3.指数分布随机数RANEXP(seed),seed为任意数值,产生参数为1的指数分布的随机数。
参数为lambda的指数分布可以用RANEXP(seed)/lambda得到。
另外若Y=alpha-beta*LOG(RANEXP(seed)),则Y为位置参数为alpha,尺度参数为beta的极值分布。
若Y=FLOOR(-RANEXP(seed)/LOG(p)),那么Y是具有参数p的几何分布变量。