logo Getting Started with SAS Main menuGlossarybacknext
Exploring sample SAS programs
  Work with SAS dates and times 2 of 3   

Examples

Suppose you want to display date, time, and datetime values as recognizable dates and times in a report. The first example below demonstrates how you can display a value as a date, a time, or a date and time. This program uses the DATETIME, DATE and TIMEAMPM formats to display the value 86399 as a date and time, a calendar date, and a time, respectively. The MONTH function extracts the numeric month from the value of Date1 (86399).

The second example reads four regional meeting dates using the MMDDYY8. informat, calculates the dates on which announcements should be mailed, and writes the dates out using the DATE9. format.

Tip:
You can copy and run these programs in SAS.

   /*************************************/
   /* set system options for report     */
   /*************************************/
options nodate nonumber; 
   /*************************************/
   /* create temporary data set         */
   /*************************************/
data test;
   Time1=86399;
   format Time1 datetime.;
   Date1=86399;
   format Date1 date.;
   Time2=86399;
   format Time2 timeampm.;
   Date1Month=month(Date1);
run;
   /*************************************/
   /* print data set                    */
   /*************************************/
proc print data=test noobs;
   title 'Same Number, Different SAS Values';
   footnote1 'Time1 is a SAS DATETIME value.';
   footnote2 'Date1 is a SAS DATE value.';
   footnote3 'Time2 is a SAS TIME value.';
   footnote4 'Date1Month is the numeric month for Date1.';
run;

   /*************************************/
   /* clear any titles and footnotes    */
   /* in effect                         */
   /*************************************/
title;
footnote;

These are the data values from the PROC PRINT output:





   /*************************************/
   /* set system options for report     */
   /*************************************/
options nodate nonumber;

   /*************************************/
   /* create temporary data set         */
   /*************************************/
data meeting;
   input region $ mtg : mmddyy10.;
   sendmail=mtg-45;
   datalines;
N  11-24-99
S  12-28-99
E  12-03-99
W  10-04-99
;
run;
   /*************************************/
   /* print data set                    */
   /*************************************/

proc print data=meeting noobs;
   format mtg sendmail date9.;
   title 'When to Send Announcements';
run;

   /*************************************/
   /* clear any titles in effect        */
   /*************************************/
title;

These are the data values from the PROC PRINT output:


Main menuGlossarybacknext