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?
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.
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,
Should 1141216 be a number or a text string?
numeric
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;
worked great, thank you for your help.
Can you please help me if we want to write in reverse? as I have the main frame values but I want to convert that into SAS 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;
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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.