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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 793 views
  • 2 likes
  • 3 in conversation