First a couple of points.
It is much easier in SAS to use space delimited lists. Commas as the delimiter will make coding much harder. So if your values contain spaces then use some other character that does not appear in the data like a pipe | or a caret ^ as the delimiter.
The strings you have are not yet dates. They might look like dates to you but they don't look like dates to SAS.
Can you start with real date values? Either date literals like "31OCT2017"D, or the actual number of days like 21123. If so then it is easy.
%let datevar = 21123 "04DEC2017"d;
proc print data=data;
where enddate in (&datevar) ;
var code enddate;
format enddate yymmdd10.;
run;
If not then convert your original macro variable to a new one that you can use:
%macro convert_ymd2date(list);
%local i;
%do i=1 %to %sysfunc(countw(&list));
%sysfunc(inputn(%scan(&list,&i),yymmdd10))
%end;
%mend convert_ymd2date;
Then your code can be
%let datevar=20171031 20171204;
proc sql outobs=;
select code
, enddate format=yymmdd10.
from data
where enddate in (%convert_ymd2date(&datevar))
;
quit;
... View more