我有一堆csv文件。每个都有来自不同时期的数据:
filename file1 'JAN2011_PRICE.csv';
filename file2 'FEB2011_PRICE.csv';
...
我是否需要手动创建中间数据集,然后将它们全部附加在一起?有没有更好的方法呢?
解
从文档中可以使用:
data allcsv;
length fileloc myinfile $ 300;
input fileloc $ ; /* read instream data */
/* The INFILE statement closes the current file
and opens a new one if FILELOC changes value
when INFILE executes */
infile my filevar=fileloc
filename=myinfile end=done dlm=',';
/* DONE set to 1 when last input record read */
do while(not done);
/* Read all input records from the currently */
/* opened input file */
input col1 col2 col3 ...;
output;
end;
put 'Finished reading ' myinfile=;
datalines;
path-to-file1
path-to-file2
...
run;
答案 0 :(得分:2)
要将一堆csv文件读入单个SAS数据集,您可以使用SAS文档here中所述的单个数据步骤。您希望本节中的第二个示例使用filevar=
infile选项。
没有理由创建中间数据集。
答案 1 :(得分:2)
最简单的方法是使用通配符。
filename allfiles '*PRICE.csv';
data allcsv;
infile allfiles end=done dlm=',';
input col1 col2 col3 ...;
run;