BookmarkSubscribeRSS Feed
Elliott
Obsidian | Level 7

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?

10 REPLIES 10
OS2Rules
Obsidian | Level 7

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.

Elliott
Obsidian | Level 7

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,

art297
Opal | Level 21

Should 1141216 be a number or a text string?

Elliott
Obsidian | Level 7

numeric

art297
Opal | Level 21

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;

Elliott
Obsidian | Level 7

worked great, thank you for your help.

art297
Opal | Level 21

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;

kajal_30
Quartz | Level 8

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.

Malv72
Calcite | Level 5

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;

jakarman
Barite | Level 11

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 --<-----

sas-innovate-2024.png

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.

 

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.

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
  • 10 replies
  • 2464 views
  • 0 likes
  • 6 in conversation