BookmarkSubscribeRSS Feed
JaySwan
Calcite | Level 5

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

5 REPLIES 5
Tom
Super User Tom
Super User

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.);

manojinpec
Obsidian | Level 7

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

sasCoders_com
Calcite | Level 5

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

art297
Opal | Level 21

The info provided in the following post may be helpful: http://www.mathkb.com/Uwe/Forum.aspx/sas/26961/DB2-DATES-in-SAS

OS2Rules
Obsidian | Level 7

Hi:

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:

PROC SQL ;

CREATE TABLE DB2Table AS

SELECT *

FROM CONNECTION TO DB2

(SELECT Var1,                     

        Var2,                   

        ...etc...                   

FROM    Table           

WHERE   Table_Date >= &INT_DATE

);

quit;

run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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