从现有数据集<key,value =“”>创建哈希

时间:2015-09-07 21:16:07

标签: hash sas

是否有任何简单的方法可以从类似哈希的数据集(即一列被视为Key而另一列(如Value)处理的数据集)中在SAS中创建哈希对象?

谢谢,对不起,如果这是一个简单的问题,我是SAS的新手:)

1 个答案:

答案 0 :(得分:1)

我认为您正在寻找dataset:参数标记。我举了一个例子from the SAS doc并将其简化为最小:

data table;
    input key data $;
    datalines;
531 yellow
620 green
908 orange
143 purple
;

data _null_;
    length key 8 data $ 8;
    if (_n_ = 1) then do;
        declare hash myhash(dataset: "table");
        rc = myhash.definekey('key');
        rc = myhash.definedata('data');
        myhash.defineDone();
        call missing( key, data ); /* avoid note re uninitialized values */
    end;

    rc = myhash.find(key:908);
    put data=;
run;

您的日志应显示:

NOTE: There were 4 observations read from the data set WORK.TABLE.
DATA=orange
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

如果您拥有SAS / OR许可证,您还可以使用OPTMODEL:

proc optmodel;
    set KEY;
    str color{KEY};
    read data table into KEY=[key] color=data;
    put color[908]=;
quit;