DATA STEP Functions

A SAS function is a routine that returns a value resulting from zero or more arguments. To invoke a function, write its name and then the argument or arguments for which the function is to be performed enclosed in parentheses.

Function Categories
  1. Arithmetic Functions
  2. Bitwise Logical Functions
  3. Character Functions
  4. Data Set Functions
  5. Date and Time Functions
  6. External File Functions
  7. Financial Functions
  8. Library and Catalog Functions
  9. Mathematical Functions
  10. Noncentrality Functions
  1. Quantile Functions
  2. Probability and Density Functions
  3. Random Number Functions
  4. Sample Statistic Functions
  5. Special Functions
  6. State and Zip Code Functions
  7. Trigonometric Functions
  8. Truncation Functions
  9. Variable Functions

  • Function Arguments
    Normally, when there is more than one argument, they must be separated by commas.
    FUNCTIONNAME (expression<,expression...>)
    The functions can also be written in the form:
    FUNCTIONNAME (OF variablelist)
    Examples of this form include:
      FUNCTIONNAME (OF X1-X10)
      FUNCTIONNAME (OF A B C D)
      FUNCTIONNAME (OF A--Z)

  • Function Results
    The resulting or target variable for a function is usually character if the arguments are character and numeric if the arguments are numeric. The PUT function is an exception as its result is a character value regardless of the type of argument. The default length is 8 for numeric and 200 for character target variables . Functions to which the default target variable lengths do not apply are shown below:
          Function   Target Variable Type  Target Variable Length
    
          BYTE       Character             1
          COMPRESS   character             length of first argument
          INPUT      character             width of informat
                     numeric               8
          LEFT       character             length of argument
          PUT        character             width of format
          REVERSE    character             length of argument
          RIGHT      character             length of argument
          SCAN       character             200
          SUBSTR     character             length of first argument
          TRANSLATE  character             length of first argument
          TRIM       character             length of argument
          UPCASE     character             length of argument
    

  • Function Categories
    • Arithmetic Functions
      • ABS(argument) returns absolute value
      • DIM(arrayname) returns the number of elements in a one-dimensional array or the number of elements in a specified dimension of a multidimensional array
      • DIM(arrayname<,boundn>) returns the number of elements in a one-dimensional array or the number of elements in a specified dimension of a multidimensional array
      • HBOUNDn(arrayname) returns the upper bound of an array
      • HBOUND(arrayname,boundn) returns the upper bound of an array
      • LBOUNDn(arrayname) returns the lower bound of an array
      • LBOUND(arrayname,boundn) returns the lower bound of an array
      • MAX(argument, ...) returns the largest value
      • MIN(argument, ...) returns the smallest value
      • MOD(argument, argument2) returns the remainder
      • SIGN(x) returns the sign of the argument or 0
      • SQRT(argument) returns the square root
      [Back to top]

    • Bitwise Logical Operations Functions
      • BAND(argument1,argument2) returns the bitwise logical AND
      • BLSHIFT(argument1,argument2) returns the bitwise left shift
      • BNOT(argument) returns the bitwise logical NOT
      • BOR(argument1,argument2) returns the bitwise logical OR
      • BRSHIFT(argument1,argument2) returns the bitwise logical right shift
      • BXOR(argument1,argument2) returns the bitwise logical EXCLUSIVE OR
      [Back to top]

    • Character Functions
      • BYTE(n) returns a character in the ASCII or EBCDIC collating sequence
      • COLLATE(n,m,l) returns a string of characters in collating sequence
      • COMPBL(source) removes multiple blanks between words in a character string
      • COMPRESS(source<,char>) removes characters from text
      • DEQUOTE(character-expression) removes quotes from a data value
      • INDEX(source,excerpt) returns for a pattern of characters
      • INDEXC(source,excerpt<,...>) returns the first occurrence of any one of a set of characters
      • INDEXW(source,excerpt) searches the source for a specified substring pattern that begins on a word boundary
      • LEFT(argument) left-aligns a character string
      • LENGTH(argument) returns the length of a character argument
      • LOWCASE(argument) converts all letters in an argument to lowercase
      • QUOTE(character-expression) adds double quotes to a data value
      • RANK(x) returns the position of a character in the ASCII or EBCDIC collating sequence
      • REPEAT(argument1,n) repeats characters
      • REVERSE(argument) reverses characters
      • RIGHT(argument) right-aligns a character string
      • SCAN(argument,n,delimiters) scans for words
      • SOUNDEX(argument) encodes a string to facilitate searching
      • SUBSTR(argument,position,n) extracts a substring
      • TRANSLATE(source,to,from,...) changes characters
      • TRANWRD(source,target,text) replaces or removes all occurrences of a word
      • TRIM(argument) removes trailing blanks
      • TRIMN(argument) removes trailing blanks
      • UPCASE(argument) converts to uppercase
      • VERIFY(argument1,argument2,...) validates a character value
      [Back to top]

    • Data Set Functions
      • ATTRC(dsid,attr-name) returns the value of a character attribute for a SAS data set
      • ATTRN(dsid,attr-name) returns the value of a numeric attribute for the specified SAS data set
      • CLOSE(dsid) closes a SAS data set
      • CUROBS(dsid) returns the observation number of the current observation
      • DROPNOTE(id,note-id) deletes a note marker a data set associated with a data set or a file id
      • DSNAME() returns the data set name associated with a data set identifier
      • EXIST(mem-name<,mem-type>) verifies the existence of a SAS data library member
      • FETCH(dsid<,'NOSET'>) reads the next nondeleted observation from a SAS data set
      • FETCHOBS(dsid,obsnum<,opts>) reads an observation from a SAS data set into the Data Set Data Vector
      • OPEN(>) opens a SAS data set
      • POINT(dsid,note-id) locates an observation identified by the NOTE function
      • REWIND(dsid) positions the data set pointer to the beginning of a SAS data set
      • NOTE(dsid) returns an observation ID for the current observation of a SAS data set
      [Back to top]

    • Date and Time Functions
      • DATE() returns today's date as a SAS date
      • DATEJUL(juliandate) returns a Julian date to a SAS date value
      • DATEPART(datetime) returns the date part of a SAS datetime value or literal
      • DATETIME() returns the current date and time of day
      • DAY(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, and second
      • HMS(hour,minute,second) returns a SAS time value from hour, minute, and second
      • HOUR(time) returns the hour from a SAS datetime or time value or literal
      • INTCK(interval,from,to) returns the number of time intervals
      • INTNX(int,from,num<,align>) advances a date, time, or datetime value by a given interval
      • JULDATE(date) returns the Julian date from a SAS date value or literal
      • MDY(month,day,year) returns a SAS date value from month, day, and year
      • MINUTE(time | datetime) returns the minute from a SAS time or datetime value or literal
      • MONTH(date) returns the month from a SAS date value or literal
      • QTR(date) returns the quarter from a SAS date value or literal
      • SECOND(time) returns the second from a SAS time or datetime value or literal
      • TIME() returns the current time of day
      • TIMEPART(datetime) extracts the time part of a SAS datetime value or literal
      • TODAY() returns the current date as a SAS date value
      • WEEKDAY(date) returns the day of the week from a SAS date value or literal
      • YEAR(date) returns the year from a SAS date value
      • YYQ(year,quarter) returns a SAS date value from the year and quarter
      [Back to top]

    • External File Functions
      • DCLOSE(directory-id) closes a directory
      • DINFO(directory-id,info-item) returns information about a directory
      • DNUM(directory-id) returns the number of members in a directory
      • DOPEN(fileref) opens a directory
      • DOPTNAME(directory-id,nval) returns directory attribute information
      • DOPTNUM(directory-id) returns the number of information items available for a directory
      • DREAD(directory-id,nval) returns the name of a directory member
      • FAPPEND(file-id<,cc>) appends the current record to the end of an external file
      • FCLOSE(file-id) closes an external file, directory, or directory member
      • FCOL(file-id) returns the current column position in the File Data Buffer (FDB)
      • FDELETE(fileref) deletes an external file
      • FEXIST(fileref) verifies the existence of an external file associated with a fileref
      • FGET(file-id,var<,length>) copies data from the File Data Buffer (FDB) into a variable
      • FILEEXIST(filenm) verifies the existence of an external file by its physical name
      • FILENAME(filerf,filenm<,opts>) assigns or deassigns a fileref for an external file, directory, or output device
      • FILEREF(filerf) verifies that a fileref has been assigned for the current SAS session
      • FINFO(file-id,info-item) returns a file information item
      • FNOTE(file-id) identifies the last record that was read
      • FOPEN(fref<,md<,len<,fmt>>>) opens an external file using optional mode, record-length, and record format specifications
      • FOPTNAME(file-id,nval) returns the name of an item of information about a file
      • FOPTNUM(file-id) returns the number of information items available about a file
      • FPOINT(file-id,note-id) positions the read pointer on the next record to be read
      • FPOS(file-id,nval) sets the position of the column pointer in the File Data Buffer
      • FPUT(file-id,cval) moves data to the File Data Buffer (FDB) of an external file starting at the FDB's current column position
      • FREAD(file-id) reads a record from an external file into the File Data Buffer (FDB)
      • FREWIND(file-id) positions the file pointer to the start of the file
      • FRLEN(file-id) returns the size of the last record read, or, if the file is opened for output, returns the current record size
      • FSEP(file-id,character(s)) sets the token delimiters for the FGET function
      • FWRITE(file-id<,cc>) writes a record to an external file
      • MOPEN(did,mem<,md<,len<,fmt>>>) opens a file by directory id and member name using optional mode, record-length and record format specifications
      • PATHNAME(fileref) returns the physical name of a SAS data library or an external file
      [Back to top]

    • Financial Functions
      • COMPOUND(amount,future,rate,number) returns compounded value parameters
      • DACCDB(period,value,years,rate) returns accumulated declining balance depreciation
      • DACCDBSL(period,value,years,rate) returns accumulated declining balance converting to straight-line depreciation
      • DACCSL(period,value,years) returns accumulated straight-line depreciation
      • DACCSYD(period,value,years) returns accumulated sum-of- years'-digits depreciation
      • DACCTAB(period,value,tab1,..tabn) returns accumulated depreciation from specified tables
      • DEPDB(period,value,years,rate) returns declining balance depreciation
      • DEPDBSL(period,value,years,rate) returns declining balance converting to straight-line depreciation
      • DEPSL(period,value,years) returns straight-line depreciation
      • DEPSYD(period,value,years) returns sum-of-years'-digits depreciation
      • DEPTAB(period,value,tab1,...,tabn) returns depreciation from specified tables
      • INTRR(period cash0,cash1,...) returns internal rate of return as a fraction
      • IRR(period,cash0,cash1,...) returns internal rate of return as a percentage
      • MORT(amount,payment,rate,number) returns mortgage loans
      • NETPV(rate,period,cash0,cash1..) returns net present value with rate expressed as a fraction
      • NPV(rate,period,cash0,cash1,..) returns net present value with rate expressed as a percentage
      • SAVING(future,payment,rate,number) returns future value of periodic saving
      [Back to top]

    • Library and Catalog Functions
      • CEXIST(entry<,'U'>) verifies the existence of a SAS catalog or SAS catalog entry
      • LIBNAME(lref<,lib<,eng<,opt>>>) assigns or deassigns a libref for a SAS data library
      • LIBREF(libref) verifies that a libref has been assigned
      [Back to top]

    • Mathematical Functions
      • AIRY(x) returns the value of the airy function
      • DAIRY(x) returns the value of the derivative of the airy function.
      • DIGAMMA(x) returns the derivative of the log of the GAMMA function
      • ERF(x) is the error function
      • ERFC(argument) returns the complement of the ERF function
      • EXP(argument) raises e ( 2.71828) to a specified power
      • GAMMA(x) returns the complete GAMMA function
      • IBESSEL(nu,x,kode) returns the value of the modified bessel function of order nu evaluated at x
      • JBESSEL(nu,x) returns the value of the bessel function of order nu evaluated at x
      • LGAMMA(argument) returns the natural logarithm of the GAMMA function of a value
      • LOG(argument) returns the natural logarithm (base e)
      • LOG2(argument) returns the logarithm to the base 2
      • LOG10(argument) returns the common logarithm
      • TRIGAMMA(argument) returns the second derivative of the logarithm of the gamma function (LGAMMA)
      [Back to top]

    • Noncentrality Functions
      • CNONCT(x,df,prob) returns the nonnegative noncentrality from the chi-square distribution
      • FNONCT(x,ndf,ddf,prob) returns the nonnegative noncentrality from the F distribution
      • TNONCT(x,df,prob) returns the nonnegative noncentrality parameter from a noncentral t distribution whose parameters are x, df, and nc
      [Back to top]

    • Quantile Functions
      • BETAINV(p,a,b) inverse beta distribution function
      • CINV(p,df<,nc>) the quantile for the chi-square distribution
      • FINV(p,ndf,ddf<,nc>) the quantile for the F distribution
      • GAMINV(p,a) inverse gamma distribution function
      • PROBIT(argument) inverse normal distribution function
      • TINV(p,df<,nc>) the quantile for the t distribution
      [Back to top]

    • Probability and Density Functions
      • CDF left cumulative distribution function.
      • LOGPDF | LOGPMF logarithm of the probability density or mass function.
      • PDF | PMF probability density or mass function.
        prob = CDF('id', quantile <, parameter-list>);
        dens = PDF('id', quantile <, parameter-list>);
        mass = PMF('id', quantile <, parameter-list>);
        logd = LOGPDF('id', quantile <, parameter-list>);
        logm = LOGPMF('id', quantile <, parameter-list>);

        These functions represent a new syntax to simplify the calling mechanism for computing probabilities, densities, and logarithms of densities. Note that PMF is an alias for PDF and that LOGPMF is an alias for LOGPDF.

        • 'id' identifies the distribution.
          The id must be enclosed in single quotes; valid distributions are: BERNOULLI, BETA, BINOMIAL, CAUCHY, CHISQUARED, EXPONENTIAL, F, GAMMA, GEOMETRIC, HYPERGEOMETRIC, LAPLACE, LOGISTIC, LOGNORMAL, NEGBINOMIAL, NORMAL | GAUSSIAN, PARETO, POISSON, T, UNIFORM, WALD | IGAUSS, and WEIBULL.
          Note that each distribution is minimally identified by its first four characters, except for the T and F distributions.
        • quantile is a numeric random variable.
          The quantile is a numeric random variable, and it represents the value at which you want the distribution evaluated.
        • parameter-list is a list of shape, location, and scale parameters
          The parameter-list identifies distribution-specific shape, location, and scale parameters. Consult the documentation for the parameters appropriate to each of the available distributions. Invalid arguments are not allowed, and a missing value will be returned.
      • POISSON((lambda,n) Poisson probability distribution function
      • PROBBETA(x,a,b) beta probability distribution function
      • PROBBNML(p,n,m) binomial probability distribution function
      • PROBCHI(x,df < , nc > ) chi-squared probability distribution function
      • PROBF(x,ndf,ddf < , nc > ) F distribution function
      • PROBGAM(x,a) gamma probability distribution function
      • PROBHYPR(N,K,n,x < ,r > ) hypergeometric probability distribution function
      • PROBMC probabilities and critical values (quantiles) from various distributions for multiple comparisons of the means of several groups.
        value= PROBMC(string,q,prob,df,nparms < ,parameters > );
        The PROBMC function can compute probabilities or quantiles from the one-sided or two-sided Dunnett, Range, and Maximum Modulus distributions with finite and infinite degrees of freedom. It also computes Williams test. Note that prob is the probability that the random variable is less than q. Therefore, p-values can be computed as 1-prob. See Technical Report P-229 for detail.
        • string is a character string identifying the distribution. It is one of the following: 'DUNNETT1', 'DUNNETT2', 'RANGE', 'MAXMOD,' or 'WILLIAMS'.
        • q is the quantile from the distribution. Only one of the parameters q and prob should be specified. The other should be set to missing.
        • prob is the left probability from the distribution. Only one of the parameters q and prob should be specified. The other should be set to missing.
        • df is the degrees of freedom. A missing value is interpreted as an infinite value.
        • nparms is the numbers of treatments. For DUNNETT1 and DUNNETT2, the control group is not counted.
        • parameters is the set of nparms parameters that must be specified to handle the unequal case. The meaning of parameters depends on the distribution. If parameters is not specified, equal parameters are assumed. This is usually the situation for a null hypothesis.
      • PROBNEGB(p,n,m) negative binomial probability distribution function
      • PROBBNRM(x,y,r) standardized bivariate normal distribution
      • PROBNORM(x) standard normal probability distribution function
        p= PROBBNRM(x,y,r);
        p is the returned probability.
        x is a numeric variable.
        r is a numeric correlation with -1 < = r < = 1.
        The PROBBNRM function returns the probability that an observation (x,y) from a standardized bivariate normal distribution with mean 0, variance 1, and a correlation p, is less than or equal to (a,b), that is, x < = a and y < = b.
      • PROBT(x,df < ,nc > ) Student's t distribution function
      [Back to top]

    • Random Number Functions
      • NORMAL(seed) returns a normal deviate
      • RANBIN(seed,n,p) returns an observation from a binomial distribution
      • RANCAU(seed) returns a Cauchy deviate
      • RANEXP(seed) returns an exponential deviate
      • RANGAM(seed,alpha) returns an observation from a gamma distribution
      • RANNOR(seed) returns a normal deviate
      • RANPOI(seed,lambda) returns an observation from a Poisson distribution
      • RANTRI(seed,h) returns an observation from a triangular distribution
      • RANUNI(seed) returns a uniform deviate
      • UNIFORM(seed) returns a uniform deviate
      [Back to top]

    • Sample Statistic Functions
      • CSS(argument,...) returns the corrected sum of squares
      • CV(argument,...) returns the coefficient of variation
      • KURTOSIS(argument,...) returns the kurtosis
      • MAX(argument,...) returns the largest value
      • MIN(argument,...) returns the smallest value
      • MEAN(argument,...) returns the arithmetic mean (average)
      • N(argument,....) returns the number of nonmissing arguments
      • NMISS(argument,...) returns the number of missing values
      • ORDINAL(count,arg1,arg2,...) returns the largest of the first count arguments.
      • RANGE(argument,...) returns the range
      • SKEWNESS(argument,...) returns the skewness
      • STD(argument,...) returns the standard deviation
      • STDERR(argument,...) returns the standard error of the mean
      • SUM(argument,...) returns the sum of the arguments
      • USS(argument,...) returns the uncorrected sum of squares
      • VAR(argument,...) returns the variance
      [Back to top]

    • Special Functions
      • DIFn(argument) returns the first difference for the nth lag
      • GETOPTION(optname < ,reptopt(s) > ) returns the value of a SAS system or graphics option
      • INPUT(source,< ? | ?? > informat> returns a given value using a given informat
      • INPUTC(source,informat < ,w < ,d > > ) enables you to specify a character informat at runtime
      • INPUTN(source,informat < ,w < ,d > > ) enables you to specify a numeric informat at runtime
      • LAGn(argument) returns the nth lagged value
      • PUT(source, < ? | ?? > format) returns a given value using a given format
      • PUTC(source,format < ,w < ,d > > ) enables you to specify a character format at runtime
      • PUTN(source,format < ,w < ,d > > ) enables you to specify a numeric format at runtime
      • RESOLVE(argument) returns the resolved value of an argument after it has been processed by the macro facility
      • SPEDIS(query,keyword) returns the asymmetric spelling distance between two words
      • SYMGET(argument) returns the value of a macro variable
      • SYSGET(environment-variable) returns the value of the specified host environment variable
      • SYSMSG() returns the error message or warning message from the last data set or external file function
      • SYSPROD(productname) determines if a product is licensed
      • SYSRC() returns a system error number or the exit status of the most recently called entry
      • SYSTEM(command) issues an operating system command during a SAS session
      [Back to top]

    • State and ZIP Code Functions
      • FIPNAME(fips) converts FIPS code to state name (all uppercase)
      • FIPNAMEL(fips) converts FIPS code to state name (in upper and lowercase)
      • FIPSTATE(fips) converts FIPS state codes to two-character postal code
      • STFIPS(postalcode) converts state postal codes to FIPS state codes
      • STNAME(postalcode) converts state postal codes to state names (all uppercase)
      • STNAMEL(postalcode) converts state postal codes to state name (upper and lowercase)
      • ZIPFIPS(zipcode) converts ZIP codes to FIPS state codes
      • ZIPNAME(zipcode) converts ZIP codes to state names (all uppercase)
      • ZIPNAMEL(zipcode) converts ZIP codes to state name (upper and lowercase)
      • ZIPSTATE(zipcode) converts ZIP codes to two-letter state codes
      [Back to top]

    • Trigonometric and Hyperbolic Functions
      • ARCOS(argument) returns the arc cosine
      • ARSIN(argument) returns the arc sine
      • ATAN(argument) returns the arc tangent
      • COS(argument) returns the cosine
      • COSH(argument) returns the hyperbolic cosine
      • SIN(argument) returns the sine
      • SINH(argument) returns the hyperbolic sine
      • TAN(argument) returns the tangent
      • TANH(argument) returns the hyperbolic tangent
      [Back to top]

    • Truncation Functions
      • CEIL(argument) returns the smallest integer>=argument
      • FLOOR(argument) returns the largest integer<=argument
      • FUZZ(argument) returns the integer if the argument is within 1E-12
      • INT(argument) returns the decimal portion of the value of the argument
      • ROUND(argument,roundoffunit) returns a value to the nearest roundoff unit
      • TRUNC(number, length) returns a truncated numeric value of a specified length
      [Back to top]

    • Variable Functions
      • GETVARC(dsid,var-num) returns the value of a SAS data set character variable
      • GETVARN(dsid,var-num) returns the value of a SAS data set numeric variable
      • VARFMT(dsid,var-num) returns the format assigned to a SAS data set variable
      • VARINFMT(dsid,var-num) returns the informat assigned to a SAS data set variable
      • VARLABEL(dsid,var-num) returns the label assigned to a SAS data set variable
      • VARLEN(dsid,var-num) returns the length of a SAS data set variable
      • VARNAME(dsid,var-num) returns the name of a SAS data set variable
      • VARNUM(dsid,var-num) returns the number of a SAS data set variable
      • VARTYPE(dsid,var-num) returns the data type of a SAS data set variable
      [Back to top]

    JZone.com 2000
1