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

I have a mainframe date as 1200617 and I want to use the same date in my base sas to do a data filtration.

Can anyone please help how can I convert this date to use in a base sas?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

Why are you asking again? The answer was given (please choose an answer in the other thread) :

 

data HAVE;
  *Format cYYMMDD - c= century number:  0 for 1800, 1 for 1900, 2 for 2000 ;       
  DATE =  1990401 ;
  DATEZ = input(put(18000000+DATE,z8.),yymmdd8.);
  format DATEZ date9.;
run;

It looks like for you, if C = 0 then it's 1900 and if C = 1 it's 2000, like here.

 

So you need to add 19000000.

Is this what you mean?

View solution in original post

6 REPLIES 6
Nicole_Fox
Obsidian | Level 7
I like the solution below that I found on the web. Here's the link that will credit the source and explain the solution:
https://www.experts-exchange.com/questions/28126605/Coverting-data-from-CYYMMDD-to-MM-DD-YYYY-in-SAS...

data date;
date_str = "1050527";
IF date_str = : "2" then date_str2 = "20"||SUBSTR(date_str,2);
ELSE date_str2 = "19"||SUBSTR(date_str,2);

date = input(date_str2, yymmdd8.);
/* if you wish to store the converted value as a SAS date displayed as mm/dd/yyyy */
format date mmddyys10.;
/* if you wish to store the converted value as a character displayed as mm/dd/yyyy */
new_date_str = put(date, mmddyys10.);
run;


ChrisNZ
Tourmaline | Level 20

Why are you asking again? The answer was given (please choose an answer in the other thread) :

 

data HAVE;
  *Format cYYMMDD - c= century number:  0 for 1800, 1 for 1900, 2 for 2000 ;       
  DATE =  1990401 ;
  DATEZ = input(put(18000000+DATE,z8.),yymmdd8.);
  format DATEZ date9.;
run;

It looks like for you, if C = 0 then it's 1900 and if C = 1 it's 2000, like here.

 

So you need to add 19000000.

Is this what you mean?

kajal_30
Quartz | Level 8

May I know the criteria for adding 18000000 or 19000000 ?

ChrisNZ
Tourmaline | Level 20

> May I know the criteria for adding 18000000 or 19000000 ?

Do you want a date starting with 120  to be 1920 or 2020?

kajal_30
Quartz | Level 8

I want it to be 2020 

kajal_30
Quartz | Level 8

In case mainframe data has both old and new records and we have no idea if they are from year 2020 or 1900 is there a generic way to convert them into SAS dates?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 6 replies
  • 2042 views
  • 2 likes
  • 3 in conversation