- Get link
- X
- Other Apps
SAS FUNCTIONS | INTCK | INTNX
Function: INTCK
Purpose: To return the number of intervals between two dates, two times, or two datetime values. To be more accurate, the INTCK function counts the number of times a boundary has been crossed going from the first value to the second.
Syntax: INTCK('interval<Multiple><.shift>', start-value,end-value)
-->interval placed in quotation marks.
-->multiple is an optional modifier in the interval.
-->.shift is an optional parameter that determines the starting point in an interval.
Function: INTNX
Purpose: To return the date after a specified number of intervals have passed.
Syntax: INTNX('interval', start-date, increment <,'alignment'>)
-->interval is one of the same values that are used with the INTCK function (placed in quotation marks).
-->start-date is a SAS date.
-->increment is the number of intervals between the start date and the date returned by the function.
-->alignment is an optional argument.
CODE:
Data dental;
input Patno : $5. Visit_date : mmddyy10.;
format Visit_date weekdate.;
datalines;
001 1/14/2009
002 1/17/2009
003 1/18/2009
004 1/19/2009
005 1/19/2009
006 1/20/2009
007 1/11/2009
008 1/17/2009
;
title "Listing of data set DENTAL";
proc print data=dental noobs;
run;
data followup;
set dental;
Six_months = intnx('month',Visit_date,6,'sameday');
*Check if weekend;
DayofWeek = weekday(six_months);
*Keep track of actual day for testing purposes;
Actual = Six_months;
*If Sunday add random integer between 1 and 5;
if DayofWeek = 1 then
Six_months = Six_months + ceil(ranuni(0)*5);
*If Saturday, add a random integer between 2 and 6;
else if DayofWeek = 7 then
Six_months = Six_months + ceil(ranuni(0)*5 + 1);
run;
proc print;run;
title "Six Month Appointment Dates";
proc report data=followup nowd headline;
columns Patno Visit_date Actual Six_months;
define Patno / display "Patient Number" width=7;
define Visit_date / display "Initial Date" width=15 format=weekdate.;
define Actual / display "Actual Day" width=15 format=weekdate.;
define Six_months / display "Six Month Appt." width=15
format=weekdate.;
run;
quit;
Explanation:
The introduction of the SAMEDAY alignment greatly enhanced the usefulness of the
INTNX function. If you used the INTNX function in the preceding program without the
SAMEDAY alignment, all of the dentist's patients would be coming in on the first of each
month! Not a great plan. By using the SAMEDAY alignment, the function returns a date six
months ahead, but on the same day of the month. Since this date may be a Saturday or
Sunday, adjustments need to be made. In this program, it was decided that if the six month
date fell on a Saturday or Sunday, a random day in the following week was to be chosen.
The expression ceil(ranuni(0)*5)produces a random integer from 1 to 5; the
expression ceil(ranuni(0)*5 + 1)produces a random integer from 2 to 6. For
illustration purposes, the actual date six months from the visit date was not dropped from the
data set so that you can see what happens if the follow-up date falls on a Saturday or Sunday.
Listing of data set DENTAL |
Patient Number | Initial Date | Actual Day | Six Month Appt. |
---|---|---|---|
001 | Wednesday, January 14, 2009 | Tuesday, July 14, 2009 | Tuesday, July 14, 2009 |
002 | Saturday, January 17, 2009 | Friday, July 17, 2009 | Friday, July 17, 2009 |
003 | Sunday, January 18, 2009 | Saturday, July 18, 2009 | Tuesday, July 21, 2009 |
004 | Monday, January 19, 2009 | Sunday, July 19, 2009 | Thursday, July 23, 2009 |
005 | Monday, January 19, 2009 | Sunday, July 19, 2009 | Friday, July 24, 2009 |
006 | Tuesday, January 20, 2009 | Monday, July 20, 2009 | Monday, July 20, 2009 |
007 | Sunday, January 11, 2009 | Saturday, July 11, 2009 | Wednesday, July 15, 2009 |
008 | Saturday, January 17, 2009 | Friday, July 17, 2009 | Friday, July 17, 2009 |
TRY THIS AND COMMENT ...
--PLEASE FOLLOW THE BLOG FOR MORE UPDATES...
--FOLLOW US IN FACEBOOK SASALL4YOU AND JOIN ...
--JOIN US IN FACEBOOK AND TELEGRAM CHANNEL FOR MORE UPDATES
CLICK HERE: https://t.me/SasAll4You
- Get link
- X
- Other Apps
Comments
Post a Comment