1

I have a data set with files names. These file names are text files and I want to import them create a master dataset that includes all the files. Here is my code:

%macro create_data();
proc sql noprint;
  select count(*) into :count from Filenames;* Filenames is dataset with Filenames;
  select fname into :filelist separated by " " from Filenames ;
quit;

%do i = 1 %to &count.;
 *import file iteratively;
 proc import datafile='c:\temp\filelist[i].txt' *stuck here;
 out=subset
 dbms=dlm
 replace;
 delimiter=' ';
 run;
 *stuck here as well. Trying to concatenate datasets iteratively to create master;
 data master;
  set subset;
 run;
%end;
%mend;

1 Answer 1

2

Presuming your files are structurally identical, try the following:

%macro create_data();
proc sql noprint;
  select count(*) into :count from Filenames;* Filenames is dataset with Filenames;
  select fname into :filelist separated by " " from Filenames ;
/* quit removed - as not necessary */

%do i = 1 %to &count.;
 *import file iteratively;
 /* change 1 */
 proc import datafile="c:\temp\%scan(&filelist,&i).txt" *stuck here; 
 out=subset
 dbms=dlm
 replace;
 delimiter=' ';
 run;
 *stuck here as well. Trying to concatenate datasets iteratively to create master;
 /* change 2 - if master does not exist, is created "like" subset */
 proc append base= master data= subset;
 run;
%end;
%mend;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.