使用SAS上两个不同变量的数字创建ID变量

时间:2017-04-11 16:58:08

标签: sql sas

我正在尝试在SAS上创建一个新变量。有一个名为“Statefip”的列和一个名为“countyfip”的列。我需要一个四位数的ID号,它结合了这两列。

例如:

enter image description here

创建此新变量时,如何告诉SAS遵循此格式?

1 个答案:

答案 0 :(得分:0)

使用putinput语句很容易做到这一点。 z3格式包括输出中的前导0||连接put语句,然后inputid字段转换为数字。

data have;
input statefip countyfip;
    datalines;
1 1
8 109
12 57
13 313
;
run;

data want;
set have;
id = input(put(statefip,2.) || put(countyfip,z3.),8.);
run;

proc print;

输出:

Obs    statefip    countyfip      id

 1         1            1        1001
 2         8          109        8109
 3        12           57       12057
 4        13          313       13313
相关问题