BookmarkSubscribeRSS Feed
toesockshoe
Calcite | Level 5

I'm trying to find the difference in dates of the format 01DEC2017... when I'm pulling in these dates they suddenly get converted to dates in the 1960's.

 

How can I pull these dates in and not change these dates? also how can I find the difference in dates of this format? thanks

13 REPLIES 13
PaigeMiller
Diamond | Level 26

If they get converted to a date in 1960, then you are using a datetime function on them, this won't get you the desired results.

 

To find the difference between two dates, subtract them.

--
Paige Miller
Reeza
Super User

You likely have datetime variables not dates. Use DATEPART() to get the date portions or use INTCK to find the intervals. 

 


@toesockshoe wrote:

I'm trying to find the difference in dates of the format 01DEC2017... when I'm pulling in these dates they suddenly get converted to dates in the 1960's.

 

How can I pull these dates in and not change these dates? also how can I find the difference in dates of this format? thanks


 

toesockshoe
Calcite | Level 5

I checked and it is of date9. format.

Reeza
Super User

Post a reproducible example of your problem then please.


@toesockshoe wrote:

I checked and it is of date9. format.


 

toesockshoe
Calcite | Level 5

ok so heres how I'm pulling stuff in:

 

proc sql;

create table new as

 select A.DATE as birthdate format = date9.

from rws.people A;

quit;

 

table A's DATE column looks like this:

 

20AUG2012
22MAR2015
01JUN2002
13MAR2004
02SEP2005
03AUG2012

.

.

.

 

 

and the outputted birthday column looks like

 

 

04APR1962
13NOV1960
05FEB1963
17OCT1961
10OCT1962
21OCT1962
25DEC1963

.

.

.

ballardw
Super User

@toesockshoe wrote:

I'm trying to find the difference in dates of the format 01DEC2017... when I'm pulling in these dates they suddenly get converted to dates in the 1960's.

 

How can I pull these dates in and not change these dates? also how can I find the difference in dates of this format? thanks


Show the code for how you are "pulling in these dates".

 

toesockshoe
Calcite | Level 5

in the select statement (using proc SQL) I have:

 

RWS.DATE as birthdate format = date9.

PaigeMiller
Diamond | Level 26

@ballardw wrote:

@toesockshoe wrote:

I'm trying to find the difference in dates of the format 01DEC2017... when I'm pulling in these dates they suddenly get converted to dates in the 1960's.

 

How can I pull these dates in and not change these dates? also how can I find the difference in dates of this format? thanks


Show the code for how you are "pulling in these dates".

 


And show us a portion of the data too.

 

If you do the subtraction, and you find out, for example that the difference between two dates is 22 days, and you format this difference as DATE9., you will get a date in 1960. You don't want this difference formatted.

--
Paige Miller
toesockshoe
Calcite | Level 5

so when I'm pulling in the dates (just pulling....not subtracting) the dates change from dates in the 2017 range to the 1960 range.

 

how the data looks:

 

RWS.DATE is 30OCT2007

 

then I pull it to create a new table using the statement in the above comment and it just changes to a date in the 1960's.... is that what you were asking for?

PaigeMiller
Diamond | Level 26

@toesockshoe wrote:

so when I'm pulling in the dates (just pulling....not subtracting) the dates change from dates in the 2017 range to the 1960 range.

 

how the data looks:

 

RWS.DATE is 30OCT2007

 

then I pull it to create a new table using the statement in the above comment and it just changes to a date in the 1960's.... is that what you were asking for?


You don't format the difference. It is an integer. If you don't format the difference, it looks like an integer, such as 22. If you format the difference it looks like a date in 1960.

--
Paige Miller
toesockshoe
Calcite | Level 5

I'm not formatting any difference..... I'm just pulling in the data from one dataset to another... the difference part will come later once I figure out how to pull the data correctly

Reeza
Super User

Ok, time to stop guessing. Please post your full code and sample input and/or proc contents on your data set after retrieval. 

 


@toesockshoe wrote:

I'm not formatting any difference..... I'm just pulling in the data from one dataset to another... the difference part will come later once I figure out how to pull the data correctly


 

toesockshoe
Calcite | Level 5

whoops sorry... I made a dumb dumb mistake.... I realized I was calling the wrong variable

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
  • 13 replies
  • 947 views
  • 0 likes
  • 4 in conversation