SAS按字段检查字段,并将字段名称设置为0

时间:2019-02-08 07:56:09

标签: sas

我的问题与以下主题有关: SAS check field by field。 我正在搜索将字段的值设置为0时将(设置)为字符串/列的可变名称的方法。 有一个优雅的方法吗?

最诚挚的问候!

1 个答案:

答案 0 :(得分:1)

VNAME函数将返回与数组引用相对应的变量的名称。

data Have;
   input REFERENCE_DATE  
         L_CONTRACT 
         L_CONTRACT_ACTIVITY
         L_LFC
         L_CONTRACT_CO_CUSTOMER
         L_CONTRACT_OBJECT
         L_CUSTOMER
         L_CUSTOMER_RETAIL
         L_DPD
         L_GL_ACCOUNT 
         L_GL_AMOUNT
         L_EXTRA_COST 
         L_PRODUCT;
   datalines;
450 1 9 8 6 0 4 3 0 0 0 0 0
;

data want;
  length vars_with_zero $1000;
  set have;
  array L L_CONTRACT -- L_CUSTOMER_RETAIL;

  * accumulate the names of the variables that have a zero value;
  do _n_ = 1 to dim(L);
    if L(_n_) = 0 then vars_with_zero = catx(' ', vars_with_zero, vname(L(_n_)));
  end;
run;