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

Hi there,

 

I am working with SAS dates.

 

I have the following data which represent the opening and closing dates of some businesses. 

 

Opening_Date	Closing_Date
19/02/1955	19/02/2020
23/03/1955	23/03/2025
23/03/1955	23/03/2025
28/11/1956	28/11/2026
13/04/1954	13/04/2019

 

The dates in the SAS data set are character so I used the following code to convert them in numerical form:

 

Opening_Date_New = input(Opening_Date, ddmmyy10.);

Closing_Date_New = input(Closing_Date, ddmmyy10.);

 

Later in the program, based on some conditions I want to create an Expected_Closing_Date, which is calculated by adding 80 years to the Opening_Date_New. For that I use the following code:

 

Expected_Closing_Date = intnx("year", Opening_Date_New, 80, 'sameday');

In a Data Step I format the dates by using the following code:

 

format Opening_Date_New yymmdd10. Expected_Closing_Date yymmdd10.;

 

I end up having the data attached, which look like as below:

 

Opening_Date    Closing_Date         Opening_Date_New    Expected_Closing_Date
19/02/1955	19/02/2020	     19/02/1955	    19/02/2035
23/03/1955	23/03/2025	     23/03/1955	    23/03/2035
23/03/1955	23/03/2025	     23/03/1955	    23/03/2035
28/11/1956	28/11/2026	     28/11/1956	    28/11/2036
13/04/1954	13/04/2019	     13/04/1954	    13/04/2034

 

I am trying to calculated the difference between the Opening_Date_New and Expected_Closing_Date but I am getting an error:

 

data want; 
set have; Diff = intnx('year', Opening_Date_New, Expected_Closing_Date); run;

NOTE: Invalid argument to function INTNX('year',-1777,27443) at line 139 column 8.

Any help please?

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PabloNogueras
Obsidian | Level 7

You are using the incorrect function.  Use the following instead.

 

Diff = intck('year', Opening_Date_New, Expected_Closing_Date);

View solution in original post

1 REPLY 1
PabloNogueras
Obsidian | Level 7

You are using the incorrect function.  Use the following instead.

 

Diff = intck('year', Opening_Date_New, Expected_Closing_Date);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 964 views
  • 0 likes
  • 2 in conversation