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
You are using the incorrect function. Use the following instead.
Diff = intck('year', Opening_Date_New, Expected_Closing_Date);
You are using the incorrect function. Use the following instead.
Diff = intck('year', Opening_Date_New, Expected_Closing_Date);
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.
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.