BookmarkSubscribeRSS Feed
DocMartin
Quartz | Level 8

I received a dataset in which many of the observations have a datetime value where the year is 2076 or 2077. Obviously these values are off by 60 years. So how can I modify the year value in that datetime variable so that the right year is in there.

 

ex. DOB = 02/15/2076 13:00 should be 02/15/2016 13:00

     DOB = 05/26/2077 9:35 should be 05/26/2017 9:35

 

Thanks!

Andrew

7 REPLIES 7
DocMartin
Quartz | Level 8

That does not work. When I try newdob = intnx("year", dob, -60) all I get is 1/1/1960. Plus, I need the time portion to remain stable. 

Reeza
Super User

You stated you had a datetime variable? If so, then Year is not the correct interval, it's DTYEAR I think. For the remaining values to be the same use the fourth parameter which controls the alignment. 

 

newdob = intnx("dtyear", dob, -60, 's')

 

 

PaigeMiller
Diamond | Level 26

@DocMartin wrote:

That does not work. When I try newdob = intnx("year", dob, -60) all I get is 1/1/1960. Plus, I need the time portion to remain stable. 


You have a datetime value, not a date value.

 

Use

intnx("dtyear",dob,-60)
--
Paige Miller
Reeza
Super User

Did you import this data from Excel originally?

 

DocMartin
Quartz | Level 8
Yes, unfortunately.
Reeza
Super User

@DocMartin wrote:
Yes, unfortunately.

Assuming this means you did import it from Excel, then I would suggest an approach noted here:

https://communities.sas.com/t5/Integration-with-Microsoft/Importing-date-time-variables-from-Excel-i...

 

Or 

 

There's a specific value that you need to use to account for Excel date to SAS date but I can't remember the rule, if you're sure it's 60 years this appraoch will work though.

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
  • 7 replies
  • 1130 views
  • 0 likes
  • 3 in conversation