Convert SAS date to Mainframe date

Reply
Contributor
Posts: 74

Convert SAS date to Mainframe date

How do I take a sas date in mmddyy10. format (12/16/2014) and convert it to a mainframe date format that looks like 1141216?

Super Contributor
Posts: 358

Re: Convert SAS date to Mainframe date

Hi:

It depends on what system you are using on the mainframe.

From your example, it looks like you have CYYMMDD as the format where C=century.  If C=1 then it is 2000 + year and if there is no

leading 1 then it is 1900 + year.

We usually take a SAS date in format CCYYMMDD and subtract 19000000 from that value to give us a date in this format.  In our case

we are actually going from mainframe to the server so the formula is the other way around.

Contributor
Posts: 74

Re: Convert SAS date to Mainframe date

what I am trying to do is take the sas date and convert it to the mainframe format to use in a high level filter of a mainframe file.  Right now we read in all the records, reformat the mf date to a sas date the delete the records that are not the correct date.  I would be much more efficient to strip out the unneeded records at the read in, I just need to know how to format the sas date to the mf format so I can do that.   Thanks,

PROC Star
Posts: 7,467

Re: Convert SAS date to Mainframe date

Should 1141216 be a number or a text string?

Contributor
Posts: 74

Re: Convert SAS date to Mainframe date

numeric

PROC Star
Posts: 7,467

Re: Convert SAS date to Mainframe date

There is probably a much easier way, but the following should work:

data have;

  informat date date9.;

  format date mmddyy10.;

  input date;

cards;

16dec2014

12jan2001

;

data want;

  set have;

  format date 8.;

  date=input(catt(int((year(date)-1900)/100),

       put(substr(put(year(date),4.),3,2),2.),

       put(month(date),z2.),

       put(day(date),z2.)),

       8.);

run;

Contributor
Posts: 74

Re: Convert SAS date to Mainframe date

worked great, thank you for your help.

PROC Star
Posts: 7,467

Re: Convert SAS date to Mainframe date

Glad to hear that, but 's code does exactly the same thing and will work a lot faster.  i.e.:

data have;

  informat date date9.;

  format date mmddyy10.;

  input date;

cards;

16dec2014

12jan2001

;

data want;

  set have;

  format date date2 8.;

  date=put(date,yymmddn8.)-19000000;

run;

Occasional Contributor
Posts: 10

Re: Convert SAS date to Mainframe date

If you just want the number and for it not to be a SAS date the easiest way should be

data temp;

date1 = today();

adate = put(date1,yymmddn8.)-19000000;

run;

Trusted Advisor
Posts: 3,211

Re: Convert SAS date to Mainframe date

At the moment of reading the mainframe data you can decide to skip those records not storing those in a sas-dataset.

Why are you storing/saving  them would be my first question. It is am unnecessary complicating approach to adjust before or after that.

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 9 replies
  • 1006 views
  • 0 likes
  • 5 in conversation