Thanks so much, Tom & Linlin. I actually tried Tom's suggestions first of putting a format in my %SYSFUNC and it worked! Now, it's just giving me one more small problem. Now the min and max functions are not understanding how to compare the dates because they're not numbers. Here's my code again and the corresponding log. %do i = &oldest_yr %to &newest_yr; %let newyear = %sysfunc(intnx(month,"01jan&i"d,0,sameday)); %let old_dt = %sysfunc(intnx(month,&oldest_dt,0,sameday),date9.); %let new_dt = %sysfunc(intnx(month,&newest_dt,0,sameday),date9.); %let new_yr = %sysfunc(intnx(month,&newyear,0,sameday),date9.); proc sql; create table steff.NB_ATT_plcytrm&i as select distinct * from connection to db2 ( select * from abc.table_a where effective_dt >= %sysfunc(max(&old_dt,&new_yr)) AND BSNS_BSS_CD = 'V' and crprtn_yr_cn=1 and effective_dt < %sysfunc(min(&new_dt,&new_yr)) ; %end; quit;); ERROR: Argument 1 to function MIN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number. ERROR: Argument 2 to function MIN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number. ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated. ERROR: CLI describe error: [IBM][CLI Driver][DB2/AIX64] SQL0104N An unexpected token "." was found following "effective_dt >=". Expected tokens may include: "<update_source_no_row_query>". SQLSTATE=42601 THANKS!
... View more