07-15-2011 05:36 PM
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.
07-15-2011 06:15 PM
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 .
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.);
07-22-2011 02:14 PM
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 www.sasCoders.com
07-25-2011 10:47 AM
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):
Then use in the SQL as in:
PROC SQL ;
CREATE TABLE DB2Table AS
FROM CONNECTION TO DB2
WHERE Table_Date >= &INT_DATE