So your problem just got 40 times harder. Instead of reading 40 files with a structure you know you now have to write code to read 40 files with unknown structures.
The first error is nothing, just telling you something you already knew from your earlier runs. SAS does not keep the variable named in the FILEVAR= option.
The second might just be an artifact of trying to open all 40 files at once. Hopefully it will not happen again when you try to read each file separately.
So the simplest first step is to read each one into its own dataset. You can then try to figure out if there are some that can be combined. And if you need to change the GUESSes that the code used to read the CSV made about how to define the variables so that they are consistent across the datasets. For example for a character variable PROC IMPORT (or other tools for guessing how to read a CSV file) will set the length of the variable long enough to hold the values it sees in that one file. So if if the same variable, like NAME or ADDRESS, appears in multiple files then each dataset could end up with the variable defined with different lengths. Which will cause trouble if you need to combine the datasets.
You can use your list of files to generate code to read each one.
You will need to decide what code to generate. You will need to decide on a name for the dataset for each file. If you are lucky the names of the files themselves can be used. So if, like the example name in your error message, the names are less than 32 character, consist only of letter, digits and underscores, and do not start with a digit, then you can use the base name of the file as the dataset name.
Since some (all?) of the files are ZIP files it might be better to generate code to use the %CSV2DS() macro. So first get the macro definition (and the definition of the %PARMV() macro it uses).
filename csv2ds url "https://raw.githubusercontent.com/sasutils/macros/master/csv2ds.sas";
filename parmv url "https://raw.githubusercontent.com/sasutils/macros/master/parmv.sas";
%include csv2ds;
%include parmv;
Now use your dataset to drive generating code. So if your dataset with the filenames is named CONTENTS and the variable with the filename is named FILENAME then the code to write code to a file might look like this:
filename code temp;
data _null_;
set contents;
file code ;
dsname=scan(filename,-1,'/\');
dsname=scan(dsname,1,'.');
put '%csv2ds(' filename :$quote. @;
if lowcase(scan(filename,-1,'.'))='zip' then put "zip member='*'" @;
put ',out=' dsname ',replace=1)';
run;
Now you can look at that file and see if it looks ok.
data _null_;
infile code;
input;
put _infile_;
run;
So you should see lines like this:
%csv2ds("C:\Users\Projects\ABDC_212.csv.zip" zip member='*',out=ABCD_212,replace=1)
If so then try running it
%incldue code / source2;
If you want to make permanent datasets instead of WORK dataset then add a libref into the code generated so you get something like:
%csv2ds("C:\Users\Projects\ABDC_212.csv.zip" zip member='*',out=mylib.ABCD_212,replace=1)
where mylib is the name of the libref you created that points to where you want to write the SAS datasets.
If you want to use PROC IMPROT to guess how to read the files then you will need to add a step to extract the files from the ZIP files before pointing PROC IMPORT at the extracted file.
... View more