BookmarkSubscribeRSS Feed
alepage
Barite | Level 11

Good morning,

 

I would like to know if it is possible to had : and year(datepart(datetime)) gt 2016 in a where statement of proc sql create table test as

 

Here's my test code:

 

This code is working:

 

proc sql;
create table TableToday as
select *, YEAR(DATEPART(DATETIME)) AS Year
from SASHELP.GNGSMP2
where ID in ('A' , 'B') AND Calculated Year ge 2000;
quit;

 

The following below is not working.  Does anyone could help me with that issue?

 

 

libname PRO Meta Library="PRO" METAOUT=DATA;
options nosymbolgen;
proc sql;
CONNECT TO ORACLE(AUTHDOMAIN="PRO" PATH="BI");
create table Table1 as
select primaryentityid , primaryentityclass, started, performerid, 1 as Web,
year(datepart(started)) as Year from connection to ORACLE
(
select primaryentityid, started, performerid, primaryentityclass
from activity a
where (category in ( 'WEB') and Calculated Year ge 2017)

union all
select primaryentityid, started, performerid, primaryentityclass
from activity_history ah
where (category in ('WEB')and Calculated year ge 2017)

);
DISCONNECT FROM ORACLE;
quit;

8 REPLIES 8
ChrisHemedinger
Community Manager

DATEPART is a SAS function and Oracle can't process that.  When using explicit passthrough (CONNECT statement), use an Oracle function. 


I think YEAR() works with datetime values -- so YEAR(started), or EXTRACT(YEAR from Started).  This from Googling for Oracle doc -- I haven't tested.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
ballardw
Super User

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

alepage
Barite | Level 11

Hello Kurt,

 

could you provide me an example how to do that?

ChrisHemedinger
Community Manager

Here's your code reworked in a way that (I hope) should work for Oracle.  I changed just the date functions -- not anything about your join logic.  I'm not conversant in Oracle SQL nuances.

 

libname PRO Meta Library="PRO" METAOUT=DATA;
options nosymbolgen;
proc sql;
CONNECT TO ORACLE(AUTHDOMAIN="PRO" PATH="BI");
create table Table1 as
select primaryentityid , primaryentityclass, started, performerid, 1 as Web,
 year(started) as Year from connection to ORACLE
(
	select primaryentityid, started, performerid, primaryentityclass
	from activity a
	where (category in ( 'WEB') and year(started) ge 2017)
	union all
	select primaryentityid, started, performerid, primaryentityclass
	from activity_history ah
	where (category in ('WEB')and year(started) ge 2017)
);
DISCONNECT FROM ORACLE;
quit;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
alepage
Barite | Level 11

Good morning,

 

One of my colleagues found the proper code I was looking for.

Here’s the code:

 

proc sql;
CONNECT TO ORACLE(AUTHDOMAIN="PRO_REPL" PATH="BI_PROD");
create table SoumEnLigne as
select primaryentityid , primaryentityclass, started, performerid, Year(datepart(started)) as Year, 1 as Web from connection to ORACLE
(
select primaryentityid, started, performerid, primaryentityclass
from activity a
where started >=to_date('2017-01-01', 'yyyy-mm-dd')
)
union all
select primaryentityid, started, performerid, primaryentityclass
from activity_history ah
where started >=to_date('2017-01-01', 'yyyy-mm-dd')
)
);
DISCONNECT FROM ORACLE;
quit;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 12360 views
  • 2 likes
  • 4 in conversation