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

Hi, I want to change the dateofbirth format from 

06NOV41:00:00:00              to     06/11/1941

19MAY36:00:00:00                      19/05/1936

13OCT35:00:00:00                      13/10/1935

10JAN29:00:00:00                      10/01/2029 ( this should be 10/01/1929)

 

the code is used is:

data tail.want;/*formatting the dateofbirth*/
set tail.have;
date=datepart(dateofbirth);
format date mmddyy10.;
run;

Can you help me with this? (0/01/2029 ( this should be 10/01/1929))

 

thank you in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Try setting the options before you execute the code

options yearcutoff=1926;

View solution in original post

7 REPLIES 7
novinosrin
Tourmaline | Level 20

Try setting the options before you execute the code

options yearcutoff=1926;
r_behata
Barite | Level 11

*Check the default yearcutoff option;
proc options option=yearcutoff;
run;

*Adjust the yearcutoff;
options yearcutoff=1929;


data _null_;
input dateofbirth datetime26.;

date=datepart(dateofbirth);
format date mmddyy10.;
put date=;
cards;
06NOV41:00:00:00
19MAY36:00:00:00
13OCT35:00:00:00
10JAN29:00:00:00
run;

25 data _null_;
26 input dateofbirth datetime26.;
27
28 date=datepart(dateofbirth);
29 format date mmddyy10.;
30 put date=;
31 cards;

date=11/06/1941
date=05/19/1936
date=10/13/1935
date=01/10/1929

Kurt_Bremser
Super User

Welcome to the communities!

This needs to be fixed when the data is imported to SAS in the first place.

Please show us an example of your data source.

novinosrin
Tourmaline | Level 20

I agree Sir @Kurt_Bremser  Right on!

ballardw
Super User

@Kurt_Bremser wrote:

Welcome to the communities!

This needs to be fixed when the data is imported to SAS in the first place.

Please show us an example of your data source.


And send a Nasty Gram to whoever is creating dates with 2-digit years.

ballardw
Super User

If you have dates with 2 digit years then you likely want to set the

Options yearcuttoff=1926;

Before the initial data set is read.

The option controls what 2-digit years are treated as before/after 2000.

With that option set any 2-digit year of 26 or greater will be treated as 1926, 1927 .... Anything under 26 will be treated as 2025, 2024, 2023. 00 would be 2000

 

If the data set was already created and you know that any of the dates that ended up later than 2020 or similar you could do something like:

data tail.want;
   set tail.have;
   date=datepart(dateofbirth);
   if year(date)> 2020 then date=intnx('year',date,-100,'S');
   format date mmddyy10.;
run;

The INTNX function is the SAS function for incrementing (or decrementing) date values. You specify the interval, the base value, the number of intervals to apply and optionally an alignment value. The 'S' says the "same" date but different year in this case.

Which likely works with date of birth because we shouldn't have too many people born in the future.

Other dates such as "date complete grade school" might be much more problematic as that might contain an expected date which could be 10 or more years in the future.

 

As I mentioned before: Tell how ever is creating dates with 2 digit years to stop it.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 7 replies
  • 1541 views
  • 7 likes
  • 5 in conversation