2014-02-19 73 views
1

我有一個包含文件名的數據集。這些文件名是文本文件,我想導入它們創建一個包含所有文件的主數據集。這裏是我的代碼:以編程方式將數據設置爲多個文件

%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; 

回答

2

意味着你的文件結構相同,請嘗試以下操作:

%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; 
相關問題