在SAS中附加csv文件

在SAS中附加csv文件,csv,sas,Csv,Sas,我有一堆csv文件。每个都有来自不同时期的数据: filename file1 'JAN2011_PRICE.csv'; filename file2 'FEB2011_PRICE.csv'; ... 我是否需要手动创建中间数据集,然后将它们全部附加在一起?有更好的方法吗 解决方案 根据文件,最好使用: data allcsv; length fileloc myinfile $ 300; input fileloc $ ; /* read instream dat

我有一堆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;

要将一组csv文件读入单个SAS数据集中,可以使用SAS文档中描述的单个数据步骤。您需要本节中使用
filevar=
infle选项的第二个示例


应该没有理由创建中间数据集。

最简单的方法是使用通配符

filename allfiles '*PRICE.csv';

data allcsv;
 infile allfiles end=done dlm=',';
 input col1 col2 col3 ...;
run;

我喜欢上面的方式,因为它不要求文件位于一个目录中。但如果所有人都在一个地方,这是好的。