Definie "automate".
If you need to repeat the jobs and perdform updates due to new folders and variables, sure, I would build macro programs to do the job.
But it's not a super quick task, but here are som general thoughts.
You need a libname for each folder, so have a list/dataset with paths and name for each libref, use a data step with call execute to assign them.
If they are already assigned, you could go the other way around and fetch this informaiton from DICTIONARY.LIBNAMES using proc sql;
In macro lop over the dat stes from each folder, potentially build a view on each table where you add the folder path in a new variable, and at the end concatenate all of them. If your datsets are not big you would be fine using a KEEP statement in the data step that concatenets the data. Otherwise generate a KEEP= data set option when you first read each data set.
... View more