1

I have two sas data sets as mentioned below ie Table1 and Table2. There is one common variable among these two datasets by name Account. But the problem I am facing is that the format of the data in table1 account and table2 account are diffrent as shown below. I have 2 problems here: Problem1: There are double inverted commas("") and hyphen (-) in the Table1 Account Problem2: The Table2 Account has continous numbers with different digit length. I want the Table2 Account to be a 12 digit number by prefixing required number of zero's to make them 12 digit number. Also change the format of Account number as present in Table1 so that I can pull the account numbers in Table1 matching the Table2 account numbers.

Table1

   ID    Account              dt
    1   "212-3276-45600"    454
    2   "562-3248-45674"    565
    3   "789-3946-45888"    6767
    4   "382-3776-45612"    766
    5   "232-3446-45674"    767
    6   "038-3276-45674"    77
    7   "232-3246-45674"    88

Table2

Account
562324845674
789394645888
38327645674
4

1 回答 1

1

要使用实际的数据步骤合并,您首先必须使变量在类型/格式/等中匹配。您可以在 SQL 中执行此操作:

proc sql;
create table want as select t1.account, t1.id, t1.dt
  from table1 t1, table2 t2
  where input(compress(t1.account,,'kd'),BEST12.) = t2.account;
quit;

您不能在数据步骤合并中操作合并变量,但您可以在前一个数据步骤中操作。

data table1_fixed;
set table1;
new_account = input(compress(account,,'kd'),BEST12.);
run;

然后将table2的帐户重命名为相同的名称。我不建议尝试让 t2 的帐户适合 t1,因为它更复杂。

我在这里做的是使用 compress 删除或保留不需要的字符;第三个参数“k”表示“保留”(不删除),“d”表示“数字”。所以它只保留数字并删除其余部分。然后输入将其转换为数字。

于 2013-10-30T20:41:42.707 回答