Published on :
SAS Functions CREATION_INTERNE

Date and Time Manipulation with INTNX

This code is also available in: Deutsch Español Français
Awaiting validation
The program uses a `_NULL_` DATA step to generate and display variables without creating a permanent dataset. It initializes three variables (`date`, `datetime`, `time`) and applies specific formats to them (`date7.`, `datetime16.`, `time8.`). The `INTNX` function is used to shift dates and times: by month for `date`, by datetime day for `datetime`, and by hour for `time`. The resulting values are then written to the SAS© log using the `PUT` statement.
Data Analysis

Type : CREATION_INTERNE


Data is created directly within the DATA step from date and time literals.

1 Code Block
DATA STEP Data
Explanation :
This `_NULL_` DATA block initializes date and time variables. It applies formats for display and uses the `INTNX` function to calculate new values based on time intervals (month, day, hour). Finally, it displays the results in the SAS log.
Copied!
1DATA _null_ ;
2 FORMAT date date7.
3 datetime datetime16.
4 time time8. ;
5 date=intnx('month','10oct97'd,0) ;
6 datetime=intnx('dtday','10oct97:12:34:56'dt,0) ;
7 time=intnx('hour','12:34't,0) ;
8 put date= / datetime= / time= ;
9RUN ;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.