【问题标题】:SAS PROC SQL UNION ALL - minimizes column lengthSAS PROC SQL UNION ALL - 最小化列长度
【发布时间】:2020-01-06 11:28:43
【问题描述】:

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

【问题讨论】:

  • 通常 PROC SQL 使用所有数据集中的最大长度,因此长度应为 25,但格式与第一个数据集保持一致,因此您看到的字符较少。 (或者当它是一个数字变量但长度超过 25 时的数字也不起作用)
  • 我刚刚使用了另一个数据集作为 UNION ALL 中的第一个数据集,它设置了其余表的长度。谢谢
  • 这不是我说的。它只设置格式!
  • 无论哪种方式 - 它都有效

标签: sas union-all proc-sql


【解决方案1】:

例如,@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;

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

* 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    相关资源
    最近更新 更多