BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I've got an ETL job that I want to be able to attach to multiple databases. One database has dates stored as DATETIME's and the other only as DATE's.

Is it possible to use one set of steps to convert these all to consistant SAS dates?
3 REPLIES 3
Olivier
Pyrite | Level 9
You should consider using this little program... (In a Code window.)

%LET dsIn = ... ; /* your existing DATETIME dataset*/
%LET dsOut = ... ; /* your converted dataset ; you can use the same name twice, and you will have your existing dataset replaced */
/*************************************************/
/* DO NOT EDIT ANYTHING AFTER THIS LINE */
/*************************************************/
PROC CONTENTS DATA = &dsIn (KEEP = _numeric_)
OUT = work.dictionary
NOPRINT ;
RUN ;
PROC SQL NOPRINT ;
SELECT name INTO : varToConvert SEPARATED BY " "
FROM work.dictionary
;
QUIT ;
DATA &dsOut ;
SET &dsIn ;
ARRAY datetimes &varToConvert ;
DO OVER dateTimes ;
dateTimes = DATEPART(dateTimes) ;
END ;
FORMAT &varToConvert DDMMYY10. ;
RUN ;
SPR
Quartz | Level 8 SPR
Quartz | Level 8
I noticed that the DATEPART function applied to a variable having date format (without time part) produces completely wrong results. So it is necessary to be sure that DATEPART is always applied to date-time variables.
Olivier
Pyrite | Level 9
The last remark is true. I should have added a WHERE statement in the SQL procedure. Something like :

WHERE UPCASE(format) = "DATETIME"

should focus conversion on DateTime variables only.
Message was edited by: Olivier at Sep 29, 2006 9:08 AM

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1246 views
  • 0 likes
  • 3 in conversation