Dates and times
Download
1 / 11

Dates and Times - PowerPoint PPT Presentation


  • 113 Views
  • Uploaded on

Dates and Times. SAS Date, Time and Date-Time Formats. Date Storage. SAS stores Dates, Times and Date-Time values differently. Datetime: seconds between January 1, 1960 and an hour/minute/second within a specified date Time: seconds since midnight of the current day

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Dates and Times' - prudence-bender


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Dates and times

Dates and Times

SAS Date, Time and Date-Time Formats


Date storage
Date Storage

SAS stores Dates, Times and Date-Time values differently.

  • Datetime: seconds between January 1, 1960 and an hour/minute/second within a specified date

  • Time: seconds since midnight of the current day

  • Date: days between January 1, 1960, and a specified date


Functions
Functions

Functions that extract dates and times from datetime variables

  • DATEPART(variable): extracts the date from a SAS datetime value

  • TIMEPART(variable): extracts the time from a SAS datetime value


Creating datetime variables
Creating datetime variables

Functions can convert numeric values to datetime values

  • MDY(month,day,year) gives a date value

    • birthday=mdy(8,27,90);

  • HMS(hour,minute,second)

    • hrid=hms(12,45,10);


Current dates and times
Current Dates and Times

The following functions extract current values

  • DATETIME()

  • DATE()

  • TIME()

    • These functions have no arguments


Parts of date values
Parts of date Values

  • Return numeric values from date values

    • DAY(date)

    • MONTH(date)

    • YEAR(date)

    • WEEKDAY(date)

    • QTR(date)


Parts of time or datetime values
Parts of time or datetime values

  • HOUR(<time | datetime>)

  • MINUTE(<time | datetime>)

  • SECOND(<time | datetime>)


Put and input functions
PUT and INPUT functions

  • PUT(source, format.) creates a character value

    • Source can be any format

    • Format must be the same type as the source

  • INPUT(source, <? | ??>informat.) creates a value based on the informat

    • Source is a character expression

    • ? or ?? suppress error messages in the log

    • Informat you want to apply


Examples
Examples

  • Character to numeric

    • Sale= INPUT(‘2,115,353’,comma9.)

  • Converting to character

    Data Test;

    dateval= put(123456,mmddyy8.);

    put dateval;

    run;

    Produces 01/04/98 in the SAS log


Formats and informats
Formats and Informats

  • Formats describe the way variables are written

    • Always contain a period

    • Start with a $ if the variable being modified is character, not otherwise

  • Informats describe the way variables are read

    • Always contain a period

    • Start with a $ if the variable is to be stored as character

  • Formats and informats generally have the same syntax

    • most formats are also informats and vice-versa


Useful datetime formats
Useful datetime formats

  • DATEw. writes date values in the form ddmmmyy or ddmmmyyyy

  • DATETIMEw.d writes datetime values in the form ddmmmyy:hh:mm:ss.ss

    • Note: what is printed depends on the w value

  • DOWNAMEw. writes date values as the name of the day of the week

  • WORDDATEw. writes date values in words

  • Etc. There are many more useful formats.


ad