We're missing some information, like what is the value of the macro variable &TodaysDate? And do you have a LIBNAME statement for MYFOLDER? Maybe you could provide more of the code before PROC SQL.
Nevertheless, treating dates as strings is simply a difficult way to proceed. Better to treat them as dates. Something like this:
%let todaysdate = %sysfunc(today());
%let tabledate = %sysfunc(intnx(month,&todaysdate,-1,e));
PROC SQL;
CREATE TABLE WORK.RandomName AS SELECT DISTINCT ID
FROM MyFolder.Table%sysfunc(putn(&tabledate,yymmddn8.))_I
WHERE ID = '12345678' AND CategoryID NOT IN ('45678','123789');
QUIT;
Please note: in the FROM statement, there are no spaces (your original code had spaces in there which won't work)
Please note: you said "yyyymmdd, where dd is the last day of the previous month." If this is something you have designed, make your life easier by using just yyyymm instead of yyyymmdd.
... View more