BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mreynaud
Obsidian | Level 7

 

 Hello,

I am attempting to determine the months between many observations between two columns: assign_date and completed_date in SAS EG

 

From other forums I read it looked like the used the intck function, however, it does not work for me. 

 

I noticed in most of the examples they used the intck function for two specific dates, not dates in columns. Perhaps that's why I am having errors?

 

proc print data=work.'test'n;
var  assign_date due_date;
intck('month', assign_date, completed_date);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

You've got the right function, but ...

 

PROC PRINT will only print variables that already exist in a data set.  It will not print a function derived from other variables.  You will have to create a new variable in DATA step creating a new data set.  Then print variables from that data set.

 

data new;
  set test;
  nmonths=intck('month',assign_date,completed_date);
run;
proc print data=new;
  var assign_date completed_date nmonths;
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

You need to assign the value to a variable.

MTHS = intck('month', ASSIGN_DATE, COMPLETED_DATE);
japelin
Rhodochrosite | Level 12

Since you can't use the intck function in the proc step, I think you should first calculate the value in the data step and then output it in the proc print.

mkeintz
PROC Star

You've got the right function, but ...

 

PROC PRINT will only print variables that already exist in a data set.  It will not print a function derived from other variables.  You will have to create a new variable in DATA step creating a new data set.  Then print variables from that data set.

 

data new;
  set test;
  nmonths=intck('month',assign_date,completed_date);
run;
proc print data=new;
  var assign_date completed_date nmonths;
run;

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Astounding
PROC Star

Whenever you use INTCK, you have to decide what it is you want to count.  If the dates represent 01/31/2021 and 02/02/2021, do you want to count that as 1 month?  If so, INTCK is correct (once you follow the suggestions that have been made).

andreas_lds
Jade | Level 19

@Astounding wrote:

Whenever you use INTCK, you have to decide what it is you want to count.  If the dates represent 01/31/2021 and 02/02/2021, do you want to count that as 1 month?  If so, INTCK is correct (once you follow the suggestions that have been made).


Setting the fourth parameter of intck to "C" (=continuous) should return 0 in such cases.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 987 views
  • 1 like
  • 6 in conversation