I have a macro function which is defined as follows:
%MACRO Data_Load( Years );
LIBNAME CCDW_LIB
ODBC
CONNECTION=SHAREDREAD
COMPLETE="DRIVER=SQL Server Native Client 11.0;SERVER=&CCDW_Server_Name;Trusted_Connection=Yes;DATABASE=&CCDW_Data_DB;"
SCHEMA="&CCDW_Data_Schema"
PRESERVE_TAB_NAMES=YES
PRESERVE_COL_NAMES=YES
;
/* Server and database details obscured for obvious reasons */
PROC SQL NOPRINT;
CREATE TABLE WORK.TABLE1 AS
SELECT ID
, VAL1
FROM CCDW_LIB.TABLE1
WHERE YR IN ( &Years )
;
QUIT; RUN;
%MEND;
When I invoke this as %Data_Load( 2018 ) I get an error because YR is actually defined as a VARCHAR and not a NUMERIC. So I tried adding a call to SepList in the WHERE clause (WHERE YR IN ( %SepList( &Years, nest=Q ) )), but this gets an syntax error, even though the MPRINT statement is a correctly formed SQL statement. If I put '2018' in a macro variable prior to the PROC SQL call and then use that variable, the SQL statement runs fine. In fact, I added the following just to see if they were the same and they were.
%LET Years_IN='2018';
%LET Years_IN1=%SepList( &Years, nest=Q );
%Log( "Years_IN = [&Years_IN]");
%IF &Years_IN1=&Years_IN %THEN %DO;
%Log("They Match");
%END;
%ELSE %DO;
%Log("The DONT Match");
%END;
I want to use SepList as the calling program may need more than one year. Any ideas what I am doing wrong? I am running on SAS 9.4 TS Level 1M5 on X64_10PRO if that matters.