SAS:重新排列数据步骤中的字段顺序
在 SAS 9 中,如何在简单的数据步骤中重新排列字段的顺序。
Data set2;
/*Something probably goes here*/
set set1;
run;
因此,如果 set1 具有以下字段:
Name Title Salary
A Chief 40000
B Chief 45000
那么我可以将 set2 的字段顺序更改为:
Title Salary Name
Chief 40000 A
Chief 45000 B
谢谢,
Dan
In SAS 9, how can I in a simple data step, rearrange the order the field.
Data set2;
/*Something probably goes here*/
set set1;
run;
So if set1 has the following fields:
Name Title Salary
A Chief 40000
B Chief 45000
Then I can change the field order of set2 to:
Title Salary Name
Chief 40000 A
Chief 45000 B
Thanks,
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一些快速谷歌搜索给了我这个方法:
从这里:
http://analytics.ncsu.edu/sesug/2002/PS12.pdf
Some quick googling gave me this method:
from here:
http://analytics.ncsu.edu/sesug/2002/PS12.pdf
如果数据集中有大量变量,有时使用 sql 语句而不是 datastep 会更容易。这允许您仅列出您关心顺序的变量,并使用通配符保留其他所有内容。
如果您使用大型表执行此操作,则可以通过创建视图来节省 IO 开销。这既可以应用于数据集方法,也可以应用于 proc sql 方法。
干杯
抢
If you have a very large number of variables in your dataset sometimes it is easier to use an sql statement instead of a datastep. This allows you to list just the variables whose order you care about and use a wildcard to retain everything else.
If you are doing this with a large table you can save yourself the IO overhead by creating a view instead. This can be applied to both the data set approach or the proc sql approach.
Cheers
Rob
您还可以使用信息语句来执行此操作 - 无需指定任何信息。我怀疑这比等效的保留语句稍微更有效,因为它允许 SAS 将值初始化为缺失,而不是从上一行检索它们。实际上,差异很小,并且您还可以选择使用视图。
informat 语句中指定的变量将移至数据集的左侧并按该顺序排列,其余变量保留在输入数据集中的原样。
You can also use an informat statement to do this - there is no need to specify any informats. I suspect this is slightly more efficient than an equivalent retain statement, as it allows SAS to initialise values to missing rather than retrieving them from the previous row. In practice the difference is minimal, and you also have the option of using a view.
The variables specified in the informat statement are moved to the left of the dataset and into that order, and the rest are left as they were in the input dataset.
您可以使用任何按您想要的顺序初始化 PDV 的变量(ATTRIB、ARRAY、FORMAT、INFORMAT、长度、保留)。
来源:此 SAS 注释:http://support.sas.com/kb/8/ 395.html
You can use anything that initializes the PDV with variables in the order you want (ATTRIB, ARRAY, FORMAT, INFORMAT, LENGTH, RETAIN).
Source: This SAS note: http://support.sas.com/kb/8/395.html