The code below brings in many excel files from a folder (they all contain the same variables). All the observations in the variable named "dataset" begin with "allinj" and are followed by numbers (eg allinj82614, allinj23014, allinj51614, etc) I would like to append the files into one file and keep three variables (ie clm_num, doi, x). Also, I need to add a variable into this new file that contains the variable dataset (eg allinj82614, allinj23014, allinj51614) so that it's known which excel file the data came from. Does anyone know how to do this? filename dir "C:\Users\Desktop\Test_Import\*.xls "; data new; length filename fname $ 100; infile dir eof=last filename=fname; input ; last: filename=fname; run; data a; set new; call scan(filename,6,pos3,len,'\'); drop len; filename1=substr(filename,pos3); dataset=compress(filename1,"\-_."); run; data _null_; set a; call execute('proc import datafile="C:\Users\Desktop\Test_Import\'||strip(filename1)||'" out='||strip(dataset)||'; run;'); run;
... View more