如何自动化并将位于日期顺序文件夹中的文件导入 SAS? [英] How to automate and import files that are located in date sequential folders into SAS?
问题描述
我目前有 700 个按顺序命名的文件夹.
文件夹的命名约定如下:-
2011-08-15_2011-08-152011-08-16_2011-08-162011-08-17_2011-08-17...2013-09-20_2013-09-20
每个文件夹中有 10 个具有相同命名约定的 txt 文件.
所有的txt文件都一样,我想要实现的是自动化infile,然后使用文件夹的名称,例如2011-08-15_2011-08-15
或例如的一部分.2011-08-15
然后是创建的数据集的名称.
我可以成功导入所有 txt 文件,所以那里没有问题,问题是我不想在 infile 步骤中每次都更改文件夹名称.
'C:SAS 数据Extract2011-08-17_2011-08-17abc.txt'
有没有更简单的方法来读取这些文件?我可以找到顺序 txt/csv 文件的代码,但找不到任何可以引用文件夹然后重命名数据集的代码.
您应该能够将文件夹/文件通配到单个文件引用中,例如
<上一页>文件名 allfiles "c:SAS_dataextract**.txt" ;数据全部数据;长度 fn _fn $256.;infile allfiles lrecl=256 truncover 文件名=_fn ;fn = _fn ;/* 保存文件名 */输入 ;把 _INFILE_ ;跑 ;通配符文件夹 &文件适用于 SAS Unix,不确定 SAS PC.
I currently have 700 folders that are all sequentially named.
The naming convention of the folders are as follows:-
2011-08-15_2011-08-15
2011-08-16_2011-08-16
2011-08-17_2011-08-17
...
2013-09-20_2013-09-20
There are 10 txt files within each folder that have the same naming convention.
With the txt files all being the same, what I am trying to achieve is to automate the infile and then use the name of the folder, eg 2011-08-15_2011-08-15
or part of eg. 2011-08-15
to then be the name of the created data set.
I can successfully import all the txt files so there is no issue there, the issue is i don't want to be changing the folder name each time in the infile step.
'C:SAS dataExtract2011-08-17_2011-08-17abc.txt'
Is there an easier way to read these files in? I can find code for sequential txt/csv files but can find nothing to reference a folder and then rename the data set.
You should be able to wildcard the folders/files into a single fileref, e.g.
filename allfiles "c:SAS_dataextract**.txt" ; data alldata ; length fn _fn $256. ; infile allfiles lrecl=256 truncover filename=_fn ; fn = _fn ; /* Store the filename */ input ; put _INFILE_ ; run ;
The wildcard folder & file works in SAS Unix, not sure about SAS PC.
这篇关于如何自动化并将位于日期顺序文件夹中的文件导入 SAS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!