New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
rajeshm
Quartz | Level 8

connected to database with lib statement. and using proc sql to fetch table contents from the db.

q1: how to fetch the month number(ex:08) from date?

q2: how to fetch date in 11AUG2020 format. currently getting date with timestamps.

 

2 REPLIES 2
Tom
Super User Tom
Super User

I think that Oracle does not have a DATE type. Only DATETIME.

Do you need to get the month after the data has come to SAS or are you asking for Oracle syntax to use in passthru code?

In SAS you can use the DATEPART() function to convert your datetime values into date values (basically divide by the number of seconds in a day).  You can then use the MONTH() function to get the month number from the date value.  If you want the dates to display in that style attach the DATE9 format to the date variable.

libname myora oracle .... ;
proc sql;
create table want as
  select id
       , datepart(oracle_date) as sas_date format=date9.
       , month(calculated sas_date) as sas_month format=z2.
  from myora.mytable
;
quit;
rajeshm
Quartz | Level 8

Thanks a lot. Oracle has Date datatype.

helpful: Yes, Your solution is working as expected.

 

combined 2steps:

month(datepart(post_date)) as month,  is also working fine.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 5612 views
  • 0 likes
  • 2 in conversation