如何使用 SAS 将多个 csv 文件合并为单个数据集 [英] How to merge multiple csv files into single dataset using SAS
问题描述
我有大约 2300 个 CSV 文件,每个 CSV 文件的第 1 列变量名称都不同.我想按 panelistID(第 2 列)合并所有文件并在第 1 列上运行频率以获取每个 CSV 文件的频率.请问有人可以帮忙吗?
以下文件布局示例:
File1mat1_pen1,小组成员ID0, 1007500120、1008600144、1008600210、10096001文件 2mat2_pen2,小组成员ID74、1011800240、1011800377、1012800177、10128003文件 3mat3_pen4,小组成员ID77、1012800351、101370010, 101480010, 101480020, 10157001
只需在 infile
语句上使用通配符即可读取所有文件,并且 filename=
将当前文件存储在临时变量 _f
中的选项,将其存储到 f
中.
然后相应地操作 f
和 var
.
I have ~2300 CSV files and colunm 1 variable name is different for each CSV file. I want to merge all files by panelistID (colunm 2) and run frequencies on column 1 to get frequency of each CSV file. Please can someone help?
Below example of file layout:
File1
mat1_pen1, panelistID
0, 10075001
20, 10086001
44, 10086002
10, 10096001
File2
mat2_pen2, panelistID
74, 10118002
40, 10118003
77, 10128001
77, 10128003
file 3
mat3_pen4, panelistID
77, 10128003
51, 10137001
0, 10148001
0, 10148002
0, 10157001
Simply use a wildcard on the infile
statement to read in all the files, and the filename=
option to store the current file in a temporary variable _f
, storing it into f
.
Then manipulate f
and var
accordingly.
data big ; length _f f $256. ; infile "*.csv" truncover filename=_f dlm=',' ; f = _f ; input var panellistID ; run ;
这篇关于如何使用 SAS 将多个 csv 文件合并为单个数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!