如何自动将位于日期顺序文件夹中的文件导入 SAS? [英] How to automate and import files that are located in date sequential folders into SAS?

查看:46
本文介绍了如何自动将位于日期顺序文件夹中的文件导入 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 data\Extract\2011-08-17_2011-08-17\abc.txt'

有没有更简单的方法来读取这些文件?我可以找到顺序 txt/csv 文件的代码,但找不到任何内容来引用文件夹,然后重命名数据集.

解决方案

您应该能够将文件夹/文件通配到单个文件引用中,例如

<前>filename allfiles "c:\SAS_data\extract\*\*.txt" ;数据全部数据;长度 fn _fn $256.;infile allfiles lrecl=256 trunco​​ver 文件名=_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 data\Extract\2011-08-17_2011-08-17\abc.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_data\extract\*\*.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆