首页 > 解决方案 > SAS PROC SQL UNION ALL - 最小化列长度

问题描述

我有 8 个表,所有表都包含相同的顺序和列数,而一个名为 ATTRIBUTE 的特定列包含长度为 4 到 25 的不同数据。当我使用 PROC SQL 和 UNION ALL 表时,ATTRIBUTE 列数据长度最小化为最低(4 位数)。我该如何解决,即保持数据的全长?

标签: sasunion-allproc-sql

解决方案


例如,根据@Lee

data have1;
  attrib name length=$10 format=$10.;
  name = "Anton Short";
run;

data have2;
  attrib name length=$50 format=$50.;
  name = "Pippy Longstocking of Stoyville";
run;

* column attributes such as format, informat and label of the selected columns
* in the result set are 'inherited' on a first found first kept order, dependent on 
* the SQL join plan (i.e. the order of the tables as coded for the query);

proc sql;
  create table want as
  select name from have1 union
  select name from have2
  ;

proc contents data=want varnum;
run;

Format 比 Length 短,任何较长值的输出显示都将在数据级别被截断。

在此处输入图像描述

* attributes of columns can be reset,
* (cleared so as to be dealt with in default manners),
* without rewriting the entire data set;

proc datasets nolist lib=work;
  modify want;
  attrib name format=;  * format= removes the format of a variable;
run;

proc contents data=want varnum;
run;

在此处输入图像描述


推荐阅读