You are on page 1of 6

SASTechies info@sastechies.com http://www.sastechies.

com

Using SAS functions, you SAS function: can function-name(argument-1<
◦ convert data from one data type to another. ◦ calculate sample statistics ◦ create SAS date values ◦ convert ZIP codes to state postal codes ◦ round values ◦ generate random numbers ◦ extract a portion of a character value

,argument-n>); where argument can be

◦ variables  mean(x,y,z) ◦ constants  mean(502,612,498) ◦ expressions   mean(37*2,192/5,mean(22,34,56 )) ◦ Even if the function does not require arguments, the function name must still be followed by parentheses, for example: function-name().

SAS Techies 2009

11/13/09

Automatic Character-toNumeric Conversion

INPUT (source,informat) where
◦ source indicates the character variable, constant, or expression to be converted to a numeric value ◦ a numeric informat must also be specified,

data hrd.newtemp; set hrd.temp; Salary=payrate*hours; run;

SAS Log
4 5 6 7 data hrd.newtemp; set hrd.temp; Salary=payrate*hours; run;

Explicit Character-to-Numeric Conversion
data hrd.newtemp; set hrd.temp; Salary=input(payrate,2.)*hours; run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 6:11 NOTE: The data set Hrd.Newtemp has 40 observations and 19 variables. NOTE: The data statement used 0.78 seconds.

SAS Techies 2009

11/13/09

Automatic Numeric-toCharacter Conversion

PUT (source,format) where

data hrd.newtemp; set hrd.temp; Assignment=site||'/'||department; run; SAS Log
4 data hrd.newtemp; 5 set hrd.temp; 6 SiteCode=site||department; 7 run; ---> NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 11:13 NOTE: The data set Hrd.Newtemp has 40 observations and 19 variables. NOTE: The data statement used 1.06 seconds.

◦ source indicates the numeric variable, constant, or expression to be converted to a character value ◦ a format matching the data type of the source must also be specified

Explicit Numeric-to- Character Conversion

data hrd.newtemp; set hrd.temp; Assi=put(site,2.)||'/'|| department; run;

SAS Techies 2009

11/13/09

Functin YEAR MONTH DAY MDY

Description

Form

Sample Value 2002 12 5 01/01/1960 ->> 0

Extracts the year value from a YEAR(date) SAS date value. Extracts the month value from a MONTH(date) SAS date value. Extracts the day value from a SAS date value. Contructs SAS date from the values passed to it

DAY(date)
MDY(month,day,year)

DATE() Today()

Gives the current date

Date() Today()

14686

SAS Techies 2009

11/13/09

Function SCAN SUBSTR

Usage
SCAN(argument,n,delimiters) SUBSTR(argument,position,n)

Example LastName=scan(‘How, R’,1,' ,'); Initial=substr('NsHARAD',1,1); substr(x,1,3)=‘NEW'; Where x=‘SKWEST’

TRIM INDEX

TRIM(argument) LEFT(argument) INDEX(source,excerpt)

NewAddress=trim(‘Jersey ‘) NewAddress=trim(left((‘ Jersey Found=index(‘SAS Analyst,‘SAS ')

‘) )

UPCASE LOWCASE

UPCASE(argument) UPCASE(‘sharad’) LOWCASE(argument) LOWCASE(‘ShaRAD’)

SAS Techies 2009

11/13/09