BookmarkSubscribeRSS Feed
bbortey
Calcite | Level 5

Hi guys,

 

I have converted a character variable to sas date for calculation.

After conversion I realized some future dates for instance '2Oct2027' is being converted to '2Oct 1927' instead. Please how do I correct such an error to reflect the correct sas date of '2Oct2027'.

thank you.

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Are you sure you converted the character expression to an actual SAS date? Show us your code.

bbortey
Calcite | Level 5

 

Format  CO_BORR_DOB $10.

 

CO_BORR_DOB1=input(CO_BORR_DOB ,date9.)

format CO_BORR_DOB1 date9.

 

the above is the code. The 'CO_BORR_DOB is character variable converted to numeric variable in step 2.

PeterClemmensen
Tourmaline | Level 20

Works for me?

 

data test;
   CO_BORR_DOB='2Oct2027';
   CO_BORR_DOB1=input(CO_BORR_DOB ,date9.);
   format CO_BORR_DOB1 date9.;
run;

proc print data=test;
run;
ballardw
Super User

@bbortey wrote:

Hi guys,

 

I have converted a character variable to sas date for calculation.

After conversion I realized some future dates for instance '2Oct2027' is being converted to '2Oct 1927' instead. Please how do I correct such an error to reflect the correct sas date of '2Oct2027'.

thank you.


What you say is quite likely related to the use of two-digit years some where. Depending on the value of your option YEARCUTOFF a two-digit year is assumed to be in 1900's if the value is less.

Run this code snippet:

proc options option=yearcutoff;run;

and see if the log shows something like:

 

 YEARCUTOFF=1926   Specifies the first year of a 100-year span that is used by date informats and
                   functions to read a two-digit year.

or any value smaller than 1927.

 

The solution, depending on your range of dates may be to set the YEARCUTOFF later than your problem year.

OR provide examples of the actual original character values and the code you used to do the conversion.

For instance when I run this code:

data example;
   x='02OCT27';
   /* my yearcutoff is 1926 which I believe is the current default for 
SAS 9.4*/ y=input(x,date7.); format y date9.; run;

The Y value is 02OCT1927.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1317 views
  • 2 likes
  • 3 in conversation