Interview Questions   Tutorials   Discussions   Programs   Videos

# SAS - Explain intnx, intcx functions?

593
views
asked mar September 20, 2014 06:30 AM

Explain intnx, intcx functions?

INTNX function advances a date, time, or datetime value by a given interval, and returns a date, time, or datetime value. Ex: INTNX(interval,start-from,number-of-increments,alignment)

intck will give the difference between two dates, you have the option to get the difference in days, months and year.

intnx will give the next or previous dates from the given date, for example if you wish to know the date after 10 days from the present date, you can get it by intnx, also if you want to get the 10 days earlier date from the present date yu can get it.

let me explain you the difference more clearly from the below code

/get the difference between two dates/

``````data have;
input dob : ddmmyy8. today : ddmmyy8.;
format dob today date9.;
cards;
03051983 21122012
;
run;
``````

data want; set have; /* in days/ age_days=intck('day',dob,today); / in months/ age_months=intck('month',dob,today); / in years*/ age_years=intck('year',dob,today); run;

``````/*date after 10 days*/

data next;
set have;
/*    after 10 days date*/
next_days=intnx('day',today,10);
/* after 10 months date*/
next_month=intnx('month',today,10);
/* after 10 years date*/
next_year=intnx('year',today,10);
format next_days next_month next_year date9.;
run;
``````

As you can see from the above code, intck can give the difference between two dates in days, months and years, however yrdif can give difference between two dates in only years. So intck is more flexible than yrdif.

flag

### Join with account you already have

Preview

Online-Classroom Classes
www.writeabc.com

1 person following this question

Question tags

sas × 1

Asked 1 year and 1 month ago ago
Number of Views -593