Functions Review Fall10

Embed Size (px)

Citation preview

  • 8/13/2019 Functions Review Fall10

    1/16

    SA S Fu n c t i o n sExample

    Second Edition

    Ron Cody

  • 8/13/2019 Functions Review Fall10

    2/16

    Summary

    Examination of SAS Functions and Calls inthe SAS programming LanguageOrganized into Chapters of related categories(such as character or statistics functions)Update of earlier version to include SASfeatures found in SAS 9.2

  • 8/13/2019 Functions Review Fall10

    3/16

    Summary

    SAS FunctionsComputation or manipulation returning a singlevalue in the format: Value=name(arguments) ;

    SAS Calls Stand alone SAS statementMay return more than a single value.

  • 8/13/2019 Functions Review Fall10

    4/16

    The Author Ron Cody

    Has worked with SAS since 1977

    Retired professor from Robert WoodJohnson Medical School.

    Private consultant and instructor for SAS

    Author of many SAS

    programming books.Presented at Many SUGI/SGFExcellent presentations

  • 8/13/2019 Functions Review Fall10

    5/16

    Strengths

    It fills the intended purpose by covering manyof the most used functions within SASIt is easy to follow and has many relevantexamplesLayout into categories and groups is welldone and thoughtful

    Has a useful list of functions althoughsome functions seem to be missing.

  • 8/13/2019 Functions Review Fall10

    6/16

    Weaknesses

    I can not keep my copy on my desk.You need to have an idea of what you wantto accomplish.It does not go much beyond what can befound in the SAS manuals

  • 8/13/2019 Functions Review Fall10

    7/16

    Recommend?

    This book is an excellent resource for anyoneworking within the SAS datastep forcalculations and manipulation.

  • 8/13/2019 Functions Review Fall10

    8/16

    Learning & Tips

    Character Functions

    COMPRESS(string, compress -list, modifiers)

    Regularly used function for compressing outcharacters. Now has modifiers to identify wholegroups of charcters (e.g. d digits, a letters, s allspace characters.

  • 8/13/2019 Functions Review Fall10

    9/16

    Learning & Tips

    Character Functions

    CATS(string-1, ) or

    CALL CATS(result, string-1 )Concatenate the listed strings into one variable resultstripping both leading and trailing blanks.Reminder use of length statement or $200

  • 8/13/2019 Functions Review Fall10

    10/16

    Learning & Tips

    Character Functions

    COUNTW(string, ,

  • 8/13/2019 Functions Review Fall10

    11/16

    Learning & Tips

    Character Functions

    NOTDIGIT(string )

    Identify location of any non-digit in a stringRelated functions include anydigit, anyalpha,nonalpha, anyspace, anypunct , etc

  • 8/13/2019 Functions Review Fall10

    12/16

    SAS regular expressions dropped in this

    edition.Basic tutorial or overview in the manual. An Introduction to Perl Regular Expressions in SAS 9, RonaldCody, SUGI 29 Perl Regular Expressions, Kenneth Borowaik, SAS Global Forum2007 .Some Simple Perl Regular Expressions Examples in SAS 9,Selvaratnam Sridharma, SAS Global Forum 2010.

    Learning & Tips

    Perl Regular Expressions

    http://www2.sas.com/proceedings/sugi29/265-29.pdfhttp://www2.sas.com/proceedings/sugi29/265-29.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://support.sas.com/resources/papers/proceedings10/089-2010.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/forum2007/135-2007.pdfhttp://www2.sas.com/proceedings/sugi29/265-29.pdfhttp://www2.sas.com/proceedings/sugi29/265-29.pdf
  • 8/13/2019 Functions Review Fall10

    13/16

    CONSTANT(constant) Returns a constant value PI, e, EULER,EXACTINT.

    RAND(distribution )Generates random numbers based on many (21+)

    distributions. Can be used in place of otherrandom functions.Use the Call STREAMINIT to start with a knownseed.

    Learning & Tips

    Math and Numeric and Other

  • 8/13/2019 Functions Review Fall10

    14/16

    GEODIST(lat-1, long-1, lat-2, long-2 )

    Distance (straight line) between two sets of lat andlong co-ordinates.Options allow:

    m returns miles

    k returns kilometers (this is the default)d locations in degrees (default)r locations are in radians

    Learning & Tips

    Other

  • 8/13/2019 Functions Review Fall10

    15/16

    Other Books

    The Little SAS Book: A primer by Delwicheand Slaughter.

  • 8/13/2019 Functions Review Fall10

    16/16

    Questions?