0% found this document useful (0 votes)
12K views

SAS Slides 5: Functions

Learning Base SAS, Advanced SAS, Proc SQl, ODS, SAS in financial industry, Clinical trials, SAS Macros, SAS BI, SAS on Unix, SAS on Mainframe, SAS interview Questions and Answers, SAS Tips and Techniques, SAS Resources, SAS Certification questions... visit http://sastechies.blogspot.com

Uploaded by

SASTechies
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT or read online on Scribd
0% found this document useful (0 votes)
12K views

SAS Slides 5: Functions

Learning Base SAS, Advanced SAS, Proc SQl, ODS, SAS in financial industry, Clinical trials, SAS Macros, SAS BI, SAS on Unix, SAS on Mainframe, SAS interview Questions and Answers, SAS Tips and Techniques, SAS Resources, SAS Certification questions... visit http://sastechies.blogspot.com

Uploaded by

SASTechies
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT or read online on Scribd
You are on page 1/ 6

SASTechies

[email protected]
http://www.sastechies.com
 Using SAS functions, you SAS function:
can function-name(argument-1<
,argument-n>); where
◦ convert data from one argument can be
data type to another.
◦ calculate sample statistics ◦ variables  mean(x,y,z)
◦ create SAS date values ◦ constants  mean(502,612,498)
◦ convert ZIP codes to state ◦ expressions  
mean(37*2,192/5,mean(22,34,56))
postal codes
◦ Even if the function does not
◦ round values require arguments, the function
◦ generate random name must still be followed by
numbers parentheses, for example:
function-name().
◦ extract a portion of a
character value

SAS Techies 2009 11/02/21


 Automatic Character-to- INPUT (source,informat)
Numeric Conversion where
data hrd.newtemp; ◦ source indicates the character
set hrd.temp;
variable, constant, or expression
to be converted to a numeric
Salary=payrate*hours;
value
run;
◦ a numeric informat must also be
specified,
SAS Log
Explicit Character-to-Numeric
Conversion
4 data hrd.newtemp;
5 set hrd.temp;
6 Salary=payrate*hours;
7 run;

NOTE: Character values have been converted


data hrd.newtemp;
to numeric values at the places given set hrd.temp;
by: (Line):(Column). 6:11
Salary=input(payrate,2.)*hours;
NOTE: The data set Hrd.Newtemp has 40 observations
and 19 variables.
run;
NOTE: The data statement used 0.78 seconds.

SAS Techies 2009 11/02/21


 Automatic Numeric-to- PUT (source,format) where
Character Conversion ◦ source indicates the numeric
variable, constant, or expression
to be converted to a character
data hrd.newtemp; value
set hrd.temp; ◦ a format matching the data type
Assignment=site||'/'||department; of the source must also be
specified
run;
SAS Log Explicit Numeric-to- Character
Conversion
4 data hrd.newtemp;
5 set hrd.temp;

data hrd.newtemp;
6 SiteCode=site||department;
7 run;

---> NOTE: Numeric values have been converted to set hrd.temp;


character values at the places given by: (Line):
(Column). 11:13 Assi=put(site,2.)||'/'||
NOTE: The data set Hrd.Newtemp has 40 observations and
department;
19 variables.
NOTE: The data statement used 1.06 seconds.
run;

SAS Techies 2009 11/02/21


Functin Description Form Sample Value
YEAR Extracts the year value from YEAR(date) 2002
a SAS date value.
MONTH Extracts the month value MONTH(date) 12
from a SAS date value.
DAY Extracts the day value from a DAY(date) 5
SAS date value.
MDY Contructs SAS date from the 01/01/1960 ->> 0
values passed to it MDY(month,day,year)

DATE() Gives the current date Date() 14686


Today()
Today()

SAS Techies 2009 11/02/21


Function Usage Example

SCAN SCAN(argument,n,delimiters) LastName=scan(‘How, R’,1,' ,');

SUBSTR SUBSTR(argument,position,n) Initial=substr('NsHARAD',1,1);


substr(x,1,3)=‘NEW'; Where x=‘SKWEST’

TRIM TRIM(argument)
LEFT(argument) NewAddress=trim(‘Jersey ‘)
NewAddress=trim(left((‘ Jersey ‘) )
INDEX INDEX(source,excerpt)

Found=index(‘SAS Analyst,‘SAS ')

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

SAS Techies 2009 11/02/21

You might also like