在 sas 数据集中重新排列变量 - 按字母顺序 [英] Rearranging variables in a sas dataset- alphabetical order

查看:9
本文介绍了在 sas 数据集中重新排列变量 - 按字母顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 500 列数据集,我想按字母顺序重新排列所有变量.除了在 set 语句之前使用 retain 语句之外,我怎么能以其他方式做到这一点?

解决方案

可以动态生成变量名列表,使用PROC SQL创建新的数据集.

<上一页>过程 sql ;选择名称到 :VARLIST 中,以 ', ' 分隔来自dictionary.columns其中 libname = 'SASHELP'和 memname = 'CLASS'按名称排序;退出 ;过程 sql ;创建表排序为选择&VARLIST来自 sashelp.class ;退出 ;

I have like 500 columns of dataset, and I want to rearrange all the variables in an alphabetical order. How can I do that in any other way than using retain statement before set statement?

解决方案

You can generate the list of variable names dynamically, and create a new dataset using PROC SQL.

proc sql ;
  select name into :VARLIST separated by ', '
  from dictionary.columns
  where libname = 'SASHELP'
    and memname = 'CLASS' 
  order by name ;
quit ;

proc sql ;
  create table ordered as
  select &VARLIST
  from sashelp.class ;
quit ;

这篇关于在 sas 数据集中重新排列变量 - 按字母顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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