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);

sas-innovate-2024.png

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.

 

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
  • 1 reply
  • 515 views
  • 0 likes
  • 2 in conversation