BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

I'm aware that INTCK counts the number of intervals between two periods, but I'd like to get a truncated version of the actual count (i.e. 12 rather than 12.3 or 12.7).

 

I think this code does it but I'm wonder if there is function that would do the same rather than multiple lines of code

 

data _null_;
format s_dt l_dt alt_end date9.;
s_dt = mdy(12,31,2008);
l_dt = mdy(1,1,2010);
months = intck('month',s_dt,l_dt);
alt_end = intnx('month',s_dt,months,'same');
if l_dt lt alt_end then trunc_month=months-1;
else trunc_month=months;
putlog _all_;
run;

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

I believe you're looking for the intck() continuous method.

data test;
  format s_dt l_dt alt_end date9.;
  s_dt = mdy(12,16,2008);
  l_dt = mdy(1,15,2010);
  months_1 = intck('month',s_dt,l_dt);
  months_2 = intck('month',s_dt,l_dt,'c');
  alt_end  = intnx('month',s_dt,months_2,'same');
  output;
  s_dt = mdy(12,15,2008);
  l_dt = mdy(1,15,2010);
  months_1 = intck('month',s_dt,l_dt);
  months_2 = intck('month',s_dt,l_dt,'c');
  alt_end  = intnx('month',s_dt,months_2,'same');
  output;
run;
proc print data=test; run;

Patrick_0-1706837043602.png

 

 

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

I believe you're looking for the intck() continuous method.

data test;
  format s_dt l_dt alt_end date9.;
  s_dt = mdy(12,16,2008);
  l_dt = mdy(1,15,2010);
  months_1 = intck('month',s_dt,l_dt);
  months_2 = intck('month',s_dt,l_dt,'c');
  alt_end  = intnx('month',s_dt,months_2,'same');
  output;
  s_dt = mdy(12,15,2008);
  l_dt = mdy(1,15,2010);
  months_1 = intck('month',s_dt,l_dt);
  months_2 = intck('month',s_dt,l_dt,'c');
  alt_end  = intnx('month',s_dt,months_2,'same');
  output;
run;
proc print data=test; run;

Patrick_0-1706837043602.png

 

 

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
  • 1 reply
  • 221 views
  • 0 likes
  • 2 in conversation