Help using Base SAS procedures

DB2 Date9 format To SAS Serial Date....

Posts: 24

DB2 Date9 format To SAS Serial Date....

Posting for a friend who is working with DB2 for the first time and has a DB2 Date in the format of Date9.

Neither one of us has any idea what this date looks like.

She wants the date to be formatted like this: 20110906  (yyyymmdd)

Anyone know the correct way to take this DB2 Date9 filed and create a SAS Serial date then we can format it to 20110906.

TIA, Jay

Super User
Super User
Posts: 6,502

Re: DB2 Date9 format To SAS Serial Date....

Is the variable already pulled into a SAS dataset using SAS/Access?  I have not worked with DB2 and did not find any Date9 format for DB2 using google.  So I assume that you already have a SAS variable.

Do a PROC CONTENTS on your dataset and see if the variable has been created as numeric or character.

If it is numeric then you probably just want to change the format attached to the variable using a FORMAT statement.

YYMMDDn8. is the SAS format for YYYYMMDD .

Try :

   FORMAT mydatevar YYMMDDn8. ;

If you want to create a new character variable then use the PUT function.

  newvar = PUT(mydatevar, YYMMDDn8.);

If you actually have a character variable that is in SAS date9 format then you can use the INPUT function to convert it to a DATE value.

   newdatevar = INPUT(mycharvar, DATE9.);

   format newdatevar YYMMDDn8.;

Or you might need to combine the two.

   newvar = PUT( INPUT( mycharvar, DATE9.) , YYMMDDn8.);

Frequent Contributor
Posts: 138

Re: DB2 Date9 format To SAS Serial Date....

Some more information about the query would help in replying  Smiley Happy

New Contributor
Posts: 4

DB2 Date9 format To SAS Serial Date....

In your question you mention that you have no idea what the date "looks like" in DB2.

Usually a data base is going to store the date as a datetime.  So you will want to get just the datepart of the datetime when you read it out of db2.

mySASdate = datepart(db2Date);

That will give you a SAS date that you can format any way you like.

Hope that helps. -s

Posts: 7,363

DB2 Date9 format To SAS Serial Date....

The info provided in the following post may be helpful:

Super Contributor
Posts: 358

DB2 Date9 format To SAS Serial Date....


We do this all the time (on z/OS mainframe)

First, set the date as in: (the date passed to DB2 needs the double quotes):

     CALL SYMPUT('INT_DATE',"'"||PUT(sas_date,YYMMDDD10.)||"'");

Then use in the SQL as in:





(SELECT Var1,                     



FROM    Table           

WHERE   Table_Date >= &INT_DATE




Ask a Question
Discussion stats
  • 5 replies
  • 6 in conversation