Dear All,
I need to import many text files into sas, i found a sas code at support SAS: http://support.sas.com/kb/41/880.html and modified it. But i still have some problems getting my desired result.
(I changed the dirctory in the code into my dir)
1.
filename DIRLIST pipe 'dir "C:\Users\*.txt" ';
data dirlist ;
infile dirlist lrecl=200 truncover;
input line $200.;
if input(substr(line,1,10), ?? mmddyy10.) = . then delete;
length file_name $ 100;
file_name="c:\Users\"||scan(line,-1," ");
keep file_name;
data _null_;
set dirlist end=end;
count+1;
call symput('read'||left(count),file_name);
call symput('dset'||left(count),substr(file_name,118,7));
if end then call symput('max',count);
run;
%put &read;
log: WARNING: Apparent symbolic reference READ not resolved.
%put &dset;
log: WARNING: Apparent symbolic reference DSET not resolved.
%put &max;
I got the correct dirlist data file, but the two macro variables are always empty.
2. I manully typed in the drictory of last data file and its data name into macro variables read and dset and tested for the following macro:
%macro readin;
%local i;
%do i=1 %to 1;
proc import datafile="&&read&i"
out=%scan(&dset,&i) dbms=dlm replace;
delimiter='|';
getnames=yes;
run;
%end;
%mend readin;
%readin;
I think there is something wrong with the satement: datafile="&&read&i" , cause, SAS read the first data file in that folder, while i assigned info of the last dat file to the macro variabels.
Thank you for your help!!
Best wishes.
... View more