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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 615 views
  • 1 like
  • 6 in conversation