首页 > 解决方案 > 如何在 SortedBy 字段中显示来自 PROC CONTENTS 的排序方法?

问题描述

我试图表明我的数据已在我的 PROC 内容输出中排序。在此输出中有一个名为“SortedBy”的属性,其中显示了内容的排序方式(据我所知)。

我的问题是,我怎样才能让我的输出如下所示:

在此处输入图像描述

这是我的代码:

/*Not sorted*/
proc contents data = I.projects;
run;

/*Sorted*/
proc sort data = WORK.projects out = projects;
by REGION descending POL NAME;
run;
proc contents data = WORK.projects;
run;

标签: sas

解决方案


选择SORTEDBY输出表;正如@Bill 提到的先前提交ODS TRACE ON将列出输出表。

proc sort data=sashelp.cars out=cars;
  by descending make model type;
run;

ods select sortedby;

proc contents data=cars;
run;

跟踪信息出现在 SAS 日志中

67   ods trace on;
68   proc contents data=cars;
69   run;


Output Added:
-------------
Name:       Attributes
Label:      Attributes
Template:   Base.Contents.Attributes
Path:       Contents.DataSet.Attributes
-------------

Output Added:
-------------
Name:       EngineHost
Label:      Engine/Host Information
Template:   Base.Contents.EngineHost
Path:       Contents.DataSet.EngineHost
-------------

Output Added:
-------------
Name:       Variables
Label:      Variables
Template:   Base.Contents.Variables
Path:       Contents.DataSet.Variables
-------------

Output Added:
-------------
Name:       Sortedby
Label:      Sortedby
Template:   Base.Contents.Sortedby
Path:       Contents.DataSet.Sortedby
-------------
NOTE: PROCEDURE CONTENTS used (Total process time):
      real time           0.05 seconds
      cpu time            0.03 seconds


70   ods trace off;

您还可以SORTEDBY使用数据步进函数检索数据集属性ATTRC

data before (keep=sortedby);
  when = 'BEFORE';
  ds = open('cars');
  sortedby = attrc(ds,'SORTEDBY');
  ds = close (ds);
run;

* sort … ;

data after (keep=sortedby);
  when = 'AFTER';
  ds = open('cars');
  sortedby = attrc(ds,'SORTEDBY');
  ds = close (ds);
run;

data compare;
  set before after;
run;

推荐阅读