数据集的排序顺序
SAS中有没有固有的方法来查找数据集的排序顺序?
Is there any inherent method in SAS to find the sort order of a dataset?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
SAS中有没有固有的方法来查找数据集的排序顺序?
Is there any inherent method in SAS to find the sort order of a dataset?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
如果 sas 没有对数据进行排序,但您认为它可能已排序,您可以尝试像已排序一样处理它,并处理可能会或可能不会发生的错误。
可以在宏中检测和重置错误状态,但这种方法可能会变得混乱。 更多信息请此处
If sas didn't sort the data but you think it might be sorted, you can try to process it as though it's sorted and deal with the errors that may or may not occur as a result.
Error states can be detected and reset in macro, but that approach is likely to get messy. More info on that here
我假设您正在解决的问题是尝试确定数据集是否需要以编程方式进行排序。 我们使用的最佳解决方案是在有疑问时简单地使用 proc sort。
当然,您可能会说,这是开销和处理。是的,但是如果数据集已经正确排序,则 proc sort 会知道这一点,并让您的代码以最少的处理继续进行。 它内置了“如果已排序则继续”逻辑。
如果这不是您想要解决的问题,请详细说明,我们会看看是否可以提供帮助。
I'm assuming that the problem you are solving is trying to determine whether a dataset needs to be sorted in a programmatic manner. The best solution we've used is to simply use proc sort when in doubt.
Of course you might say, that's overhead and processing.. Well yes, but if the dataset is already sorted correctly, proc sort with know it and let your code move on with minimal processing. It has the "if sorted then move on" logic built in.
If this isn't the problem you are trying to solve, elaborate and we'll see if we can help.
您可以使用 Attrc 函数。
文档位于 http://support.sas.com/ onlinedoc/913/getDoc/en/lrdict.hlp/a000147794.htm
它类似于以下内容
You can use the
Attrc
function.Docs at http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a000147794.htm
It goes something like the following
如果数据确实已被“排序”,那么是的。 在 proc 内容生成的输出的底部有一个关于排序信息的小表。
使用已按某种排序顺序的数据构建的数据集可能没有附加此信息,您将需要开始探索数据以确定其顺序。
If the data has indeed been "sorted", yes. There is a small table concerning sort information at the bottom of the output produced by proc contents.
Datasets that have been built with data that was already in some kind of sort order may not have this information attached to them and you will need to begin to explore the data to determine its order.
正如 Sassy 所说,SAS 知道数据集是否已排序的唯一方法是它是否进行了排序,或者您是否明确告诉它排序顺序。 如果您没有执行这些步骤中的任何一个,它将不知道数据是否按任何类型的顺序排列。
我喜欢 AFHood 尝试对其进行排序的想法。 如果 SAS 知道它是这样排序的,它只会告诉您并且不会再这样做。
这里有一些研究数据排序的其他想法......享受吧。
如果你只想手动查看,可以使用 proc content data=libname.data;run; 并查看输出。 有一个属性叫sorted。 如果您使用窗口模式,您可以右键单击资源管理器中的数据集并选择属性,然后单击详细信息选项卡并查看排序依据值。
对于编程测试方法,您可以使用过程内容中的输出数据集。 Sorted 和 Sortedby 列将告诉您数据集是否已排序以及按哪个变量排序。 通过运行下面的代码来尝试一下。
As Sassy says, the only way SAS knows if a data set is sorted is if it did the sorting, or if you explicitly tell it the sort order. If you haven't done either of these steps, it will have no idea if the data is in any type of order.
I like AFHood's idea of just trying to sort it. If SAS knows it is sorted that way it will just tell you and won't do it again.
Here are some other ideas for investigating data sorting...Enjoy.
If you just want to look at it manually, you can use proc contents data=libname.data;run; and look at the output. There is an attribute called sorted. If you are using the windowing mode you can right click on the data set in the explorer and choose properties, then click the details tab and see the sortedby values.
For a programmatic testing approach, you can use an output data set from proc contents. The sorted and sortedby columns will tell you if the data set is sorted and which variable it is sorted by. Try it by running the code below.