SAS仅插入到ARRAY(示例)数据集中的第一行 [英] SAS insert to ARRAY only (example) first row from dataset

查看:65
本文介绍了SAS仅插入到ARRAY(示例)数据集中的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点问题。我只需要插入第一个数组(例如)第一个数组,最好按字段插入。
我该怎么办?如果您也指出如何逐列插入(我将来将能够加载选定的列),将不胜感激。

I have bit a problem. I need insert to Array only (example) first array, best field by field. How Can I do it? I will be grateful if also you point how insert column by column (I will be able to load chosen columns in the future).

data have;
infile DATALINES dsd missover;
input varr1 varr2 varr3;
CARDS;
1, 2, 3
2, 3, 4 
5, 4
4, 3
9, 4, 1
6,
;run;

data want;
   set have;
    array L[3] _temporary_ ;

if _n_ = 1 then 
    do;
        do i = 1 to 3;
            %LET j = i;
            L[i] = varr&i;  /*in this place I have problem*/
            put L[i];
        end;
    end;
run;


推荐答案

您不需要宏,也不确定为什么您需要临时数组 L

You don't need macro, and not sure why you need temporary array L.

array语句可用于组织变量,以便可以在变量中访问它们。数组方式。循环遍历变量数组以将值复制到临时数组中。

The array statement can be used to organize variables so they can be accessed in an array manner. Loop over the variable array in order to copy the values into the temporary array.

临时数组的元素不可用于输出,并且 not 正常的隐式程序数据矢量(PDV)行为的一部分会重置变量丢失。

The elements of a temporary array are not available for output, and not part of normal implicit program data vector (PDV) behaviors that would reset variables to missing.

data want;
  set have;
  array V varr1-varr3;
  array L[3] _temporary_;

  * save first rows values in temporary array for use in other rows;
  if _n_ = 1 then 
    do index = 1 to dim(V);
      L[index] = V[index];
    end;

  * … for example … ;

  array delta_from_1st [3];  * array statement implicitly creates three new variables that become part of PDV and get output;
  do index = 1 to dim(V);
    delta_from_1st[index] = V[index] - L[index];
  end;      
run;

这篇关于SAS仅插入到ARRAY(示例)数据集中的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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