SAS 函数
- 格式:doc
- 大小:37.00 KB
- 文档页数:6
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。
第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 calculated函数
SAS的计算函数包括:
1. ABS函数:ABS函数可以用来计算给定数值的绝对值。
2. CEIL函数:CEIL函数用于向上取整,也就是将给定数值转换为最接近的较大的整数值。
3. FLOOR函数:FLOOR函数用于向下取整,也就是将给定数值转换为最接近的较小的整数值。
4. INT函数:INT函数用来计算一个参数的精确整数值,该值是小于或等于参数值的最大整数值。
5. MOD函数:MOD函数用于计算余数或求模。
6. ROUND函数:ROUND函数用来对数值进行四舍五入,将给定数值转换为指定小数位数的数值。
7. SQRT函数:SQRT函数用于计算正平方根值。
sas次方函数SAS次方函数是指SAS软件中的POW函数,它可以实现对数值的幂次计算。
SAS次方函数的使用非常广泛,可以用于数据分析、建模以及统计等方面,下面笔者将从使用方法、相关参数、实例应用等方面进行详细介绍。
一、使用方法SAS次方函数主要通过POW函数来实现,其语法格式如下:POW(x,y)其中,x和y都是数值型变量或常量,表示底数和指数,POW函数的作用就是求x的y次方。
二、相关参数SAS次方函数中的参数比较简单,只需要输入底数和指数即可,例如:data _null_;x=2;z=POW(x,y);put z=;run;打印出来的结果就是z=8。
这个例子中,x和y分别表示底数和指数,z表示x的y次方值。
三、实例应用SAS次方函数在实际应用中非常广泛,例如:1. 数据建模在建立某些数据模型时,常常需要对某些数据进行幂次计算,其实这时候我们就可以使用SAS次方函数,例如:data _null_;input x y;datalines;3 24 35 4;/*计算x的y次方*/z=LOG10(POW(x,y));put z=;run;2. 统计分析在进行统计分析时,有时需要将一组数据进行幂次转化,例如:data _null_;input x y;datalines;1 22 23 24 2;/*计算x的y次方*/z=POW(x,y);put z=;run;3. 概率计算在概率计算中,常常需要用到倍率计算,例如:data _null_;input p n;datalines;0.3 30.4 40.5 5;/*计算概率值*/z=POW(p,n);put z=;run;四、总结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常用函数介绍
SAS的功能非常强大和全面,这一点在函数上得到了极为充分的体现,SAS 8.2中共有25大类函数,功能涉及到文件管理、金触、数学计算、统计计算、字符串处理、货币转换等各个方面。
因篇幅限制,这里无法将数百种函数一一解释,只列举出饺为常用的十大类函数,关于这些函数的详细信息,以及术列出的货币转换函数、金融函数、地区以及邮政编码函数等相关信息请大家参见SAS帮助。
1.算术函数
2.字符函数
3.数学函数
4.概率与密度函数
5.分位数函数
6.随机函数
7.样本统计函数
8.三角函数
9.截断函数
10.日期时间函数。
SAS语言概述SAS提供了一种完善的编程语言。
类似于计算机的高级语言,SAS用户只需要熟悉其命令、语句及简单的语法规则就可以做数据管理和分析处理工作。
因此,掌握SAS编程技术是学习SAS的关键环节。
在SAS中,把大部分常用的复杂数据计算的算法作为标准过程调用,用户仅需要指出过程名及其必要的参数。
这一特点使得SAS编程十分简单。
一、SAS程序SAS程序是SAS语句的有序集合。
SAS程序可分为两部分:1.数据步(DATAStep)2.过程步(PROCStep)在一份SAS程序中,通常有一个数据步和一个过程步.有时可能有多个数据步和多个过程步。
数据步是为过程步准备数据的且将准备好的数据放在数据集中,过程步是把指定数据集中的数据计算处理并输出结果。
二、SAS语句SAS语句是以SAS关键词开头、后跟SAS名、特殊字符或操作符组成,并且以分号结尾。
一个SAS语句规定了一种操作或为系统提供某些信息。
1.SAS关键字关键字是系统已赋于确定意义的一个单词。
在SAS语言里,除了赋值、求和、注释等语句外,多数语句是以其关键字作为开头的。
如DATA、FORMA,PROC、INFILE等都是相应语句的关键字。
2.SAS名在SAS语句中,可能出现的SAS名有变量名,数据集名,输出格式名,过程名,选择项名,数组名和语句标号名。
还有SAS对文件的一种特殊称呼叫逻辑库名和文件逻辑名。
SAS名是字母或下划线开头后跟宇母或数宇或下划线的字符串,字符个数不多于八个。
空格和特殊宇符(如$,@,#等)不许在SAS名中出现。
另外,SAS保留了一些特殊的变量名并赋于特定的意义,这些变量都是以下划线开头和结尾,如N_表示数据步已执行过的次数。
三、语句描述记号(1)关键字用英文书写,在写程序时,这些词必须严格以给出的拼写形式书写。
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:替代循环的函数。
【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函数大全一、数学函数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 幂函数中的特定函数在 SAS(Statistical Analysis System)中,幂函数用于计算一个数的幂次方。
SAS 提供了多个幂函数,包括 EXP、 LOG、 POW 等。
本文将详细解释这些特定函数的定义、用途和工作方式。
1. EXP 函数定义EXP 函数用于计算指数函数的值。
指数函数的数学定义为:y=e x,其中 e 为自然对数的底(约等于2.71828)。
在 SAS 中,EXP 函数的输入参数是 x,返回值是 e 的 x 次幂。
用途和工作方式EXP 函数在统计和数学领域有广泛应用。
在 SAS 中,EXP 函数常用于以下情况:•计算指数模型的预测值:在回归分析中,指数模型的因变量 y 与自变量 x 呈指数关系,EXP 函数可以根据模型参数和 x 的值计算预测值 y。
•数据变换:有时候,数据的分布不满足正态分布的要求,通过取对数和指数变换可以使数据接近正态分布,EXP 函数可以用于还原变换后的数据。
EXP 函数的工作方式非常简单。
通过输入想要计算的幂次方的参数 x,EXP 函数返回 e 的 x 次幂的值。
下面是一个示例代码:data exp_example;x = 1;y = exp(x);put y=;run;在上面的代码中,x 被赋值为 1,EXP 函数计算 e 的 1 次幂,结果被赋值给 y。
通过 PUT 语句,可以将计算结果输出到日志中。
2. LOG 函数定义LOG 函数用于计算自然对数(底为 e)的值。
自然对数的数学定义为:y=ln(x),其中 x 是函数的输入参数。
在 SAS 中,LOG 函数的输入参数是 x,返回值是 x的自然对数。
用途和工作方式LOG 函数在统计和数学领域也有广泛应用。
在 SAS 中,LOG 函数常用于以下情况:•数据变换:有时候,数据的分布不满足正态分布的要求,通过取对数和指数变换可以使数据接近正态分布,LOG 函数用于取对数变换。
•数据处理:在一些统计分析中,经常要对数据进行对数变换,以便于对变量之间的关系进行线性分析。
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的正弦、余弦、正切函数。
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位的奇数。