BookmarkSubscribeRSS Feed
UshaLatha
Obsidian | Level 7

I have  a code to select data of current and next month (for a particular year). But this would not work in December, as the values of months picked up will be 12 and 13:

 

proc sql;

create table test1 as

select distinct id from table A

where year(date)>= 2012

and (month(date)=(month(today()) + 1) OR (month(date)=month(today())));

quit;

 

So, now changed the code to following:

proc sql;

create table test2 as

select distinct id from table A

where year(date)>= 2012

and (month(intnx('month',date,0))=month(intnx('month',date,1,'s')) OR (month(date)=month(today()));

quit;

 

The values month(intnx('month',date,0)) and month(intnx('month',date,1,'s')) are coming correctly when testing in sas dataset. But its not working in Proc SQL.

The log says:

SAS_SQL: Unable to convert the query to DBMS specific SQL statement due to an error.

ACCESS_ENGINE: SQL statement was not passed to the DBMS, SAS will do the processing.

 

Due to this the counts are not matching for test1 and test2 results (expecting same result counts for rundate 23OCT2018).

 

Please help resolve this.

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

intnx is a SAS function that is why.  You have to remember that SQL in a proc SQL when run locally is using the inbuilt SAS SQL compiler, which has access to the SAS functions.  If you are passing through the SQL code, then that code is taken as test to the database SQL compiler and run there, the SQL parser will not have the SAS functions.  Therefore you need to build your SQL using the destination platform, so if it is the database, then you would need to use the database functions to perform such a test, or write it yourself.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1 reply
  • 856 views
  • 0 likes
  • 2 in conversation