Exampler.org SAS PYTHON HTML
SAS Introduction
SAS Abs
SAS Anydigit
SAS ASC
SAS Case Stmnt.
SAS Ceiling
SAS Change type
SAS Char
SAS CMISS
SAS Coalesc
SAS Coalescec
SAS Concatenate
SAS Constant
SAS Create Table
SAS DateTime
SAS Day
SAS Find
SAS Floor
SAS HMS
SAS Holiday
SAS HOUR
SAS Import
SAS Informats
SAS Inobs
SAS Input Stmt.
SAS Int
SAS INTNX
SAS Length
SAS Libname
SAS Loops
SAS Minute
SAS Month
SAS MDY
SAS NMISS
SAS Notdigit
SAS Lowercase
SAS Outobs
SAS Put Stmt.
SAS Rename
SAS Round
SAS Scan
SAS Substr
SAS Sum
SAS STNAME
SAS STNAMEL
SAS Time
SAS Trunc
SAS Uppercase
SAS Week
SAS Year
SAS Financial Functions
SAS Compound

SAS INTNX Function

What is it?

Syntax:

  • intnx(increment_type,date_or_datetime,increment_amount);

SAS INTNX Function:


 SAS INTNX Example:




Data work.my_data_file;

    Result_1 = INTNX('dtday','15apr21:00:10:48'dt,1);
    Result_2 = PUT(Result_1, datetime19.);
    Result_3 = INTNX('dtsec','15apr21:00:10:48'dt,1);
    Result_4 = PUT(Result_3, datetime19.);
    Result_5 = INTNX('dtmin','15apr21:00:10:48'dt,1);
    Result_6 = PUT(Result_5, datetime19.);
    Result_7 = INTNX('dthour','15apr21:00:10:48'dt,1);
    Result_8 = PUT(Result_7, datetime19.);


    Result_9 = INTNX('day','15apr21:00:10:48'dt,1);
    Result_10 = PUT(Result_9, date.);
    Result_11 = INTNX('week','15apr21:00:10:48'dt,1);
    Result_12 = PUT(Result_11, date.);
    Result_13 = INTNX('month','15apr21:00:10:48'dt,1);
    Result_14 = PUT(Result_13, date.);
    Result_15 = INTNX('year','15apr21:00:10:48'dt,1);
    Result_16 = PUT(Result_15, date.);

Run;





What's happening in the script above?

  • The INTNX(); Function is incrementing the Date and or DateTime function by the specified interval type and interval amount
  • The PUT Function is converting the supplied Datetime to something Human readable either in the format of another DateTime or Date


INTNX and PUT Examples:

Variable Input Output Description
Result_1 INTNX('dtday','15apr21:00:10:48'dt,1); 1934150400 A SAS numeric representation of the datetime
Result_2 PUT(Result_1, datetime19.); 16Apr2021:00:00:00 A reformated datetime that has been incremented by 1 day
Result_3 INTNX('dtsec','15apr21:00:10:48'dt,1); 1934064649 A SAS numeric representation of the datetime
Result_4 PUT(Result_3, datetime19.); 15Apr2021:00:10:49 Reformatted and incremented by 1 second
Result_5 INTNX('dtmin','15apr21:00:10:48'dt,1); 1934064660 A SAS numeric representation of the datetime
Result_6 PUT(Result_5, datetime19.); 15APR2021:00:11:00 Reformatted and incremented to the next minute; notice it is not 60 seconds later
Result_7 INTNX('dthour','15apr21:00:10:48'dt,1); 1934067600 A SAS numeric representation of the datetime
Result_8 PUT(Result_7, datetime19.); 15APR2021:01:00:00 Reformatted and incremented to the next hour; notice it is not 60 minutes later
Result_9 INTNX('day','15apr21'd,1); 22386 Numeric Represenation (NR)
Result_10 PUT(Result_9, date.); 16APR21 Reformatted and incremented by 1 day
Result_11 INTNX('week','15apr21'd,1); 22388 (NR)
Result_12 PUT(Result_11, date.); 18APR21 Incremented to the following sunday (e.g. the next week; not 7 days later)
Result_13 INTNX('week','15apr21'd,1); 22401 (NR)
Result_14 PUT(Result_13, date.); 01MAY21 Incremented to the first of the following month
Result_15 INTNX('week','15apr21'd,1); 22646 (NR)
Result_16 PUT(Result_15, date.); 01JAN22 Incremented to the first of the following year

See also; PUT Function

See also; TODAY Function

See also; MYD Function




Connect via LinkedIn

Kevin Regan

Have an article, idea, found a typo, want to contribute? Shoot me an email Here


Below are links to some Udemy Data Science Courses. I've been using Udemy for a number of years now, and I've found their courses super helpful, maybe you will also.