Sample 24733: Use SASĀ® date and time variables to create a SAS datetime value
Create a SAS datetime variable using the DHMS function.
Note:
A SAS datetime is the number of seconds occurring
since January 1, 1960.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
In the first step, date and time values are read into a SAS data set with the appropriate informats. In the next step, the DHMS function combines the date and time to create a SAS datetime value. The DHMS function contains four arguments: days, hours, minutes, and seconds. Since a SAS date is stored as the number of days since January 1, 1960, this variable belongs in the first argument, 0 values are inserted for the next two arguments, and the SAS time is stored as seconds since midnight so this belongs as the fourth argument.
data one;
input sasdate :mmddyy8. time :time5.;
datalines;
01011999 5:00
;
run;
data two;
set one;
sasdatetime=dhms(sasdate,0,0,time);
format sasdatetime datetime22.;
run;
proc print;
run;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs sasdate time sasdatetime
1 14245 18000 01JAN1999:05:00:00
Create a SAS datetime variable using the DHMS function.
| Type: | Sample |
| Topic: | SAS Reference ==> Functions ==> Date and Time SAS Reference ==> DATA Step
|
| Date Modified: | 2005-12-16 03:02:58 |
| Date Created: | 2004-09-30 14:09:08 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |