BookmarkSubscribeRSS Feed
himself
Quartz | Level 8

Hi, 

 

I have a quick question on SAS dates, just wondering which one to use.

data check;
y='22jun2015'd;
z='16sep2015'd;

weeks=(z-y)/7;
weeksfn=intck('week',y,z);
run;

So Assuming we have this type of question According to the SAP the following should be used to categorize time in weeks 

so for weeks we have 12.285714286

while weeksfn we have 12.

 

SAP says 

The time intervals will be defined as:

  • ‘0 – 12 weeks’
  • ’>12 – 26 weeks’
  • ‘> 26 weeks’

So will this be categorized under 0-12 as per the intck function 

or it will be categorized as >12-26 weeks as per long division?

 

 

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@himself wrote:

Hi, 

 

I have a quick question on SAS dates, just wondering which one to use.

data check;
y='22jun2015'd;
z='16sep2015'd;

weeks=(z-y)/7;
weeksfn=intck('week',y,z);
run;

So Assuming we have this type of question According to the SAP the following should be used to categorize time in weeks 

so for weeks we have 12.285714286

while weeksfn we have 12.

 

SAP says 

The time intervals will be defined as:

  • ‘0 – 12 weeks’
  • ’>12 – 26 weeks’
  • ‘> 26 weeks’

So will this be categorized under 0-12 as per the intck function 

or it will be categorized as >12-26 weeks as per long division?


This is completely up to you. In your program, you can handle either way, based upon your needs.

--
Paige Miller
Astounding
PROC Star

Why are you complicating matters?  Don't even compute weeks.  Just use the number of days.  For example:

 

length interval $ 15;
if z-y < 84 then interval = '0 - 12 weeks';

Details to watch for:

 

  • Should you include both the start points and end point in your interval, or just one of them?  
  • Do interval definitions require <  vs.  <=  ?
  • Could either z or x take on a missing value?  Those could get assigned to the lowest interval, probably not a good result.

Regardless of the details, all of your requirements can be fulfilled using days, without calculating weeks.

Tom
Super User Tom
Super User

Just base your categories on number of days.  You can label them using the text from the SAP, but use the actual number of days in the calculations.

 

You should also learn about the extra option to INTCK() that lets you control how it counts intervals.  The default is count the number of inter boundaries crossed.  So how many Sundays are in between the two dates.  But if you use CONT for the final option it will use the actual day of the week at the start of the interval when determining the number of intervals. So that should be more like your division by 7.

 

data check;
  input (y z) (:date.);
  format y z date9.;
  days = z-y;
  weeks1 = days/7;
  weeks2 = intck('week',y,z);
  weeks3 = intck('week',y,z,'cont');
cards;
22jun2015 16sep2015
01jan2021 01mar2021
;
Obs            y            z    days     weeks1    weeks2    weeks3

 1     22JUN2015    16SEP2015     86     12.2857      12        12
 2     01JAN2021    01MAR2021     59      8.4286       9         8
himself
Quartz | Level 8
Yes, I agree with you, before I posted the question I had to read more on INTCK, but still 12.2857 seems to be greater as compared to 12.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 950 views
  • 0 likes
  • 5 in conversation