Input Dates

  • Upload
    amitmse

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

  • 8/6/2019 Input Dates

    1/2

    Informat Description Range Width Sample-------- ----------- ----- ------- ------JULIANw. Julian date 5-32 5 65001

    YYDDDDDMMYYw. date values 6-32 6 14/8/1963MONYYw. month and year 5-32 5 JUN64YYMMDDw. date values 6-32 8 65/4/29

    YYQw. year and quarter 4-32 4 65/1

    1. Reading dates in data

    Read the following data sets in SAS using a SAS program. Use datalines if convenient. Also print all these dates in DD-MM-YYYY format using proc print.

    Name Date

    ---- -----------John 1 Jan 1960Mary 11 Jul 1955Kate 12 Nov 1962Mark 8 Jun 1959

    Name Date---- ----------John 1 1 1960Mary 07/11/1955Joan 07-11-1955Kate 11.12.1962Mark 06081959

    Month Year Date----- ---- ----7 1948 111 1960 110 1970 1512 1971 10

    2. Reading 2-digit dates in data

    Read the following data sets in SAS using a SAS program. Use datalines if conven

    ient. Also print all these dates in DD-MM-YYYY format using proc print.

    Mon DD YYYY--- -- ----7 11 187 11 481 1 6010 15 7012 10 71

    3. Computations with elapsed dates: Compute everyone's age on Jan 1 2006

    Name DOB

    ---- ----------John 1 1 1960Mary 07/11/1955

  • 8/6/2019 Input Dates

    2/2

    Joan 07-11-1955Kate 11.12.1962Mark 06081959

    4. Other useful date functions

    There are a number of useful functions for use with date variables. The following is a list of some of those functions.

    Function Description Sample-------- --------------------- -----------------month() Extracts Month m=MONTH(bday);day() Extracts Day d=DAY(bday) ;year() Extracts Year y=YEAR(bday);weekday() Extracts Day of Week wk_d=WEEKDAY(bday);qtr() Extracts Quarter q=QTR(bday);

    5. Summary

    * Dates are read with date formats, most commonly date9. and mmddyy10.* Date functions can be used to create date values from their components (md

    y(m,d,y)), and to extract the components from a date value (month(),day(),etc.).

    * The yearcutoff option may be used to control where the 2000 break comes ifyou have to read two digit years.

    6. Problems to look out for

    * Dates are mixed within a field such that no single date format can read them. Solution: Read the field as a character field, test the string, and usethe input function and appropriate format to read the value into the date variab

    le.* There is no format capable of reading the date. Solution: read the date a

    s components and use a function to produce a date value.* Sometimes the default for yearcutoff is not the default for the version of

    the package mentioned above. Solution: to determine the current setting foryearcutoff simply run a program containing

    PROC OPTIONS OPTION=YEARCUTOFF; RUN;This will result in output containing the current value of yearcutoff.