SYMBOLGEN: Macro variable T_CLIENT_ID resolves to 00000031-B081-4E97-9437-F20CF874F857
proc sql;
select
COALESCE(sum(abc.step_sum),0)
into :SumLoans_12m
from
RTDM_ABT.ABT_CONTRACT abc
where abc.CLIENT_ID = "&T_CLIENT_ID"
and today() - datepart(abc.CONTRACT_BEGINDATE) <= 365
and abc.DML_FLAG NE 1
group by abc.CLIENT_ID;
quit;
(Format CONTRACT_BEGINDATE = 2021-01-14 00:00:00.000)
ERROR:
SAS_SQL: Unable to convert the query to a DBMS specific SQL statement due to an error. 152499 1621241630 no_name 0 SQL (437
ACCESS ENGINE: SQL statement was not passed to the DBMS, SAS will do the processing. 152500 1621241630 no_name 0 SQL (437
152501 1621241630 no_name 0 SQL (437
its work fo t-sql:
select coalesce(sum(step_sum),0)
from
RTDM_ABT.ABT_CONTRACT abc
where abc.client_id = '00000AAB-F0E1-4CFA-9D91-C598FCDFAB4F'
and GETDATE() - abc.CONTRACT_BEGINDATE <= 365
and abc.DML_FLAG <> 1
group by abc.client_id
where's my mistake? Thanks for your help!
Based on the error message I'm assuming you are doing SQL Pass-Thru to a DBMS i.e. the SQL code is run inside the DBMS and not run by SAS.
The error message is telling you that the SQL contains some SAS syntax that the DBMS does not understand, so the query is passed back to SAS and SAS runs the query.
My educated guess is the following function calls are probably the issue:
and today() - datepart(abc.CONTRACT_BEGINDATE) <= 365
I'd start by removing or changing those to a hardcoded value and see if the query works
I also had such an assumption and it was confirmed, after deleting this line, the code works, but how to make this script work with this line is not yet clear to me. 🤔
So now we know that's the problem, the question is how to correct the code.
The first thing we need to know is the format of abc.CONTRACT_BEGINDATE, as you're using the datepart() function I would assume it's a SAS date/time value. If it is a SAS data/time value then I think the following would work (untested):
data _null_ ;
now=datetime() ;
diff=365*24*60*60 ;
put now= datetime. now= ;
call symput("mvNow",put(now,14.2)) ;
run ;
%put mvNow= &mvNow ;
proc sql;
select
COALESCE(sum(abc.step_sum),0)
into :SumLoans_12m
from
RTDM_ABT.ABT_CONTRACT abc
where abc.CLIENT_ID = "&T_CLIENT_ID"
and &mvNow - abc.CONTRACT_BEGINDATE <= (365*24*60*60)
and abc.DML_FLAG NE 1
group by abc.CLIENT_ID;
quit;
I'm not certain this will work, as I do not use SQL pass-thru, and I'm not sure if the SAS Macro Variable will be resolved, prior to the code being passed to DBMS (I believe it does).
You might also want to change the (365*24*60*60) to 31536000 (number of seconds in 365 days)
Again this assumes abc.CONTRACT_BEGINDATE is a SAS date/time value (number of seconds since 00:00:00 01Jan1960)
CONTRACT_BEGINDATE ( 2021-01-14 00:00:00.000 )
Why dou use the DATEPART function on something that seems to be a date already?
You also do not need the GROUP BY when your WHERE condition already restricts the observations to one group.
And you may have a problem converting the UUID string to the correct type in the DBMS.
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' 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.