SAS - 向后读取文件?
我需要 SAS 读取许多大型日志文件,这些文件被设置为在底部包含最新的活动。我所需要的只是特定活动发生的最近时间,我想知道 SAS 是否可以跳过解析文件的(长)开始部分。
我在网上查找并找到了如何向后读取数据集,但这需要 SAS 首先将 .log 文件中的所有内容解析到数据集中。是否可以直接从最后开始读取文件,以便我可以在找到特定类型的最新活动时立即停止数据步骤?
我也阅读了 infile 和 firstobs 选项,但我不知道这些日志文件在解析之前需要多长时间,对吧?对我来说听起来像是第 22 条军规。那么我所描述的情况可行吗?
I need SAS to read many large log files, which are set up to have the most recent activities at the bottom. All I need is the most recent time a particular activity occurred, and I was wondering if it's possible for SAS to skip parsing the (long) beginning parts of the file.
I looked online and found how to read a dataset backwards, but that would require SAS to first parse everything in the .log file into the dataset first. Is it possible to directly read the file starting from the very end so that I can stop the data step as soon as I find the most recent activity of a particular type?
I read up on infile as well, and the firstobs option, but I have no idea how long these log files are until they are parsed, right? Sounds like a catch-22 to me. So is what I'm describing doable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会设置一个文件名管道语句来使用
tail -r
或tac
等操作系统命令以相反的顺序向 SAS 呈现文件。这样SAS就可以正常读取文件而不必担心文件有多长。I'd probably set up a filename pipe statement to use an operating system command like
tail -r
ortac
to present the file in reverse order to SAS. That way SAS can read the file normally and you don't have to worry about how long the file is.如果您的意思是解析 sas 日志文件,我不确定在实践中向后读取日志文件是否值得。例如,以下代码在我的 PC 上执行时间不到十分之一秒,并且正在写入和读取 10,000 行日志文件。您的日志文件有多大?有多少个?同样如下所示,您不必“解析”每一行上的所有内容。您可以有选择地阅读该行的某些部分,如果这不是您要查找的内容,则可以转到下一行。
If you mean parsing a sas log file, I am not sure if reading the log file backward is worth the trouble in practice. For instance, the following code executes less than a tenth of a second on my PC and it is writing and reading a 10,000 line log file. How big is your log files and how many are there? Also as shown below, you don't have to "parse" everything on every line. You can selectively read some parts of the line and if it is not what you are looking for, then you can just go to the next line.