Hi, new SAS user here, hope you guys can help! I have a list of files in a directory ending in either .txt or .dbf. I would like to read in the list of names, then import the data appropriately depending on the file type. I have managed to get the list of names, and can even use substr(file_name,max(1,length(file_name)-2)) to get the extension. What i can't do is iterate over this list of extensions in an if statement to specify the input type. It seems the %scan function is not doing what I need it to? But I'm not sure why. Can anyone help/point me in the right direction? Here is the code that I have: filename DIRLIST pipe 'dir "M:\R\SASDatasets\*" /b '; data dirlist ; infile dirlist lrecl=200 truncover; input file_name $100.; run; data _null_; set dirlist end=end; count+1; call symputx('read'||put(count,4.-l),cats('M:\R\SASDatasets\',file_name)); call symputx('dset'||put(count,4.-l),scan(file_name,1,'.')); if end then call symputx('max',count); run; %macro readin; data file_type; set dirlist; file_type = substr(file_name,max(1,length(file_name)-2)); drop file_name; run; %do i=1 %to &max; %let type = %scan(file_type, &i); %if &type='dbf' %then %do; proc import datafile="&&read&i" out=df.&&dset&i dbms=dbf; run; %end; %else %do; proc import datafile="&&read&i" out=df.&&dset&i_label dbms=dlm replace; delimiter='09'x; run; %end; %end; %mend readin; %readin;
... View more