Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SAS Functions

2,981 views

Published on

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

Published in: Technology, Education
  • Be the first to comment

SAS Functions

  1. 1. SASTechies [email_address] http://www.sastechies.com
  2. 2. <ul><li>Using SAS functions, you can </li></ul><ul><ul><li>convert data from one data type to another. </li></ul></ul><ul><ul><li>calculate sample statistics </li></ul></ul><ul><ul><li>create SAS date values </li></ul></ul><ul><ul><li>convert ZIP codes to state postal codes </li></ul></ul><ul><ul><li>round values </li></ul></ul><ul><ul><li>generate random numbers </li></ul></ul><ul><ul><li>extract a portion of a character value </li></ul></ul><ul><li>SAS function: </li></ul><ul><li>function-name (argument-1< ,argument-n>) ; where argument can be </li></ul><ul><ul><li>variables  mean( x,y,z ) </li></ul></ul><ul><ul><li>constants  mean( 502,612,498 ) </li></ul></ul><ul><ul><li>expressions   </li></ul></ul><ul><ul><li>mean(37*2,192/5, mean(22,34,56) ) </li></ul></ul><ul><ul><li>Even if the function does not require arguments, the function name must still be followed by parentheses, for example: function-name (). </li></ul></ul>SAS Techies 2009 11/13/09
  3. 3. <ul><li>Automatic Character-to-Numeric Conversion </li></ul><ul><li>data hrd.newtemp; </li></ul><ul><li>set hrd.temp; </li></ul><ul><li>Salary=payrate*hours; </li></ul><ul><li>run; </li></ul><ul><li>INPUT ( source,informat ) where </li></ul><ul><ul><li>source indicates the character variable, constant, or expression to be converted to a numeric value </li></ul></ul><ul><ul><li>a numeric informat must also be specified, </li></ul></ul><ul><li>Explicit Character-to-Numeric Conversion </li></ul><ul><li>data hrd.newtemp; </li></ul><ul><li>set hrd.temp; </li></ul><ul><li>Salary=input(payrate,2.)*hours; </li></ul><ul><li>run; </li></ul>SAS Techies 2009 SAS Log 11/13/09 4 data hrd.newtemp; 5 set hrd.temp; 6 Salary=payrate*hours; 7 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.
  4. 4. <ul><li>Automatic Numeric-to- Character Conversion </li></ul><ul><li>PUT ( source,format ) where </li></ul><ul><ul><li>source indicates the numeric variable, constant, or expression to be converted to a character value </li></ul></ul><ul><ul><li>a format matching the data type of the source must also be specified </li></ul></ul><ul><li>Explicit Numeric-to- Character Conversion </li></ul><ul><li>data hrd.newtemp; </li></ul><ul><li>set hrd.temp; </li></ul><ul><li>Assi= put(site,2.) ||'/'||department; </li></ul><ul><li>run; </li></ul>SAS Techies 2009 SAS Log data hrd.newtemp; set hrd.temp; Assignment=site||'/'||department; run; 11/13/09 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.
  5. 5. SAS Techies 2009 11/13/09 DATE() Today() Gives the current date Date() Today() 14686 MDY Contructs SAS date from the values passed to it MDY( month,day,year ) 01/01/1960 ->> 0 Functin Description Form Sample Value YEAR Extracts the year value from a SAS date value. YEAR( date ) 2002 MONTH Extracts the month value from a SAS date value. MONTH( date ) 12 DAY Extracts the day value from a SAS date value. DAY( date ) 5
  6. 6. SAS Techies 2009 11/13/09 Example LastName=scan(‘How, R’,1,' ,'); Initial=substr('NsHARAD',1,1); substr(x,1,3)=‘NEW'; Where x=‘SKWEST’ NewAddress= trim(‘Jersey ‘) NewAddress= trim(left((‘ Jersey ‘) ) Found=index(‘SAS Analyst,‘SAS ') UPCASE(‘sharad’) LOWCASE(‘ShaRAD’) Function Usage SCAN SCAN( argument,n,delimiters ) SUBSTR SUBSTR( argument,position,n ) TRIM TRIM( argument ) LEFT (argument) INDEX INDEX( source,excerpt ) UPCASE UPCASE( argument ) LOWCASE LOWCASE( argument )

×