Sas 要在多个txt文件中读取的filevar infile语句
从中我学会了如何读取多个txt文件 问题:是否可以创建宏变量来输入文件夹中的所有txt文件。说C:\Users\Desktop\(假定所有文件都是名为datasetyyymmdd的txt格式) 我有dataset20150101.txt-dataset20150806.txt,我不想在数据行中手动输入所有这些链接Sas 要在多个txt文件中读取的filevar infile语句,sas,Sas,从中我学会了如何读取多个txt文件 问题:是否可以创建宏变量来输入文件夹中的所有txt文件。说C:\Users\Desktop\(假定所有文件都是名为datasetyyymmdd的txt格式) 我有dataset20150101.txt-dataset20150806.txt,我不想在数据行中手动输入所有这些链接 data whole2; infile datalines; length fil2read $256; input fil2read $; infil
data whole2;
infile datalines;
length fil2read $256;
input fil2read $;
infile dummy filevar=fil2read end=done dsd;
do while (not done);
input name$ value1 value2;
output;
end;
datalines;
C:\Users\Desktop\dataset20150501.txt
C:\Users\Desktop\dataset20150502.txt
run;
询问操作系统存在哪些文件:
filename DataIn pipe "dir C:\Users\Desktop\dataset*.txt /S /B";
data whole2;
infile DataIn truncover;
length fil2read $256;
input fil2read $;
infile dummy filevar=fil2read end=done dsd;
do while (not done);
input name$ value1 value2;
output;
end;
run;
裸选项/B
删除不需要的信息,如上次访问日期
我添加了子文件夹选项/S
,因为dir语句会返回完整的路径名。这样,它还可以读取C:\Users\Desktop\
子文件夹中的dataset*.txt
文件。如果这不适合您,请删除/S
并使用
path2Read = "dir C:\Users\Desktop\"||fil2read;
嗨,用户,我不明白你的问题。你想实现什么?嗨,我在一个子文件夹中有未知数量的数据集文件。我想包括所有数据集。在文件名中使用通配符。请看这里的答案嗨@Dirk,谢谢你的回答。它会弹出一条错误消息错误:物理文件不存在,C:\Users\dataset1.txt。正如您所见,我不知道为什么它在没有桌面文件夹的情况下更改目录。@用户,我没有测试它,对不起。显然,光是裸选项
/B
就可以给出文件名。如果像我通常做的那样添加子文件夹选项/S
,则会得到完整的路径名。您可以在我进行更多测试时使用它;添加:files=“C:\Users\Desktop\”|| fil2read;将fil2read替换为infle中的文件:infle dummy filevar=files end=done dsd;