0
votes

I am new to SAS and I have the following problem. The database I work with has two dates in two columns and I am supposed to calculate the difference between then in months.

These dates are in format YYMM, eg.: 200603 is March 2006 and 200612 is December 2006. Difference between them should be 9 months.

I am trying to create a new column (called "difference") with the dates difference. I tried the following code:

data TIMES.TEST;
set TIMES.INPUTS;    
difference = intck('month',input(fin_period,yymmn6.),input(period,yymmn6.));
run;

It creates a new column named difference (correct) but it is all filled with dots. Nothing is calculated. Have I done something wrong? Is there another way to calculate the difference between two dates when I have such a date format?

Thanks in advance.

I use SAS Studio.

1

1 Answers

-1
votes

If period and fin_period are stored as numeric variables, you need to convert them to text before you can apply the yymmn6. informat to convert them to dates.

Here are a few examples that might help to make this clearer:

data inputs;
input period fin_period;
cards;
200603 200612
;
run;

/*Difference = .*/
data test;
set inputs;    
difference = intck('month',input(fin_period,yymmn6.),input(period,yymmn6.));
run;

data inputs2;
input period $ fin_period $;
cards;
200603 200612
;  
run;

/*Difference = -9*/
data test2;
set inputs2;    
difference = intck('month',input(fin_period,yymmn6.),input(period,yymmn6.));
run;

/*Difference = -9*/
data test3;
set inputs;    
difference = intck('month',input(put(fin_period,6.),yymmn6.),input(put(period,6.),yymmn6.));
run;