在 SAS 中附加 csv 文件
我有一堆 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;
I have a bunch of csv files. Each has data from a different period:
filename file1 'JAN2011_PRICE.csv';
filename file2 'FEB2011_PRICE.csv';
...
Do I need to manually create intermediate datasets and then append them all together? Is there a better way of doing this?
SOLUTION
From the documentation it is preferable to use:
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要将一堆 csv 文件读入单个 SAS 数据集,您可以使用 SAS 文档中所述的单个数据步骤 此处。您需要本节中的第二个示例,该示例使用
filevar=
infile 选项。没有理由创建中间数据集。
To read a bunch of csv files into a single SAS dataset, you can use a single data step as described in the SAS documentation here. You want the second example in this section which uses the
filevar=
infile option.There should be no reason to create intermediate datasets.
最简单的方法是使用通配符。
The easiest method is to use a wildcard.