如何将数据从 SAS 加载到 Teradata,其中多个 excel 文件以相同的列名称导入 SAS

How to load data from SAS to Teradata where multiple excel files are imported in SAS with the Same column name

我有 10 个 excel 具有相同列名的文件需要插入到 Teradata 中。我在 Teradata 中创建了一个包含所有列详细信息的 table 并将数据导入 SAS 。现在,我应该如何从 SAS 推送到 Teradata?为此,我需要 proc sql。

如果您已经在 Teradata 中创建了 table,一种方法是使用 proc append 或 proc sql 通过使用 libname。 Fastload 进行批量加载。示例如下

 libname teralib teradata server=server user=userid pwd=password ;
 libname saslib '/u/mystuff/sastuff/hello';

 proc append base= teralib.staging_customer_ref(fastload =yes)
 base = saslib.cust_ref;
   run;

或者在 Proc sql

中使用插入语句
    proc sql;
    insert into teralib.staging_customer_ref
    (FastLoad=YES)
   select * from saslib.cust_ref;
   quit;   

请查看下面的论文,其中讨论了将数据从 SAS 移动到 Teradata 的各种选项 http://support.sas.com/resources/papers/EffectivelyMovingSASDataintoTeradata.pdf

编辑:请完整阅读您的问题,如果您想在插入语句(在位置上起作用)中匹配名称,您可能需要创建一个宏变量并在插入语句中使用,并且在这种情况下最好使用 proc append,作为 proc 根据列名追加

proc sql noprint;
select name into :cols separated by ','
 from Dictionary.columns
 where upcase(libname) = upcase('teralib')
  and upcase(memname) = upcase('staging_customer_ref');

   proc sql;
  insert into teralib.staging_customer_ref (FastLoad=YES)
  select &cols from saslib.cust_ref;

Edit2:看起来你的两个数据集不一样(即数据类型不一样)。您可以采取以下步骤

  1. 您可以更改 Teradata table 的 DDL 并执行插入,或者也可以。

  2. 使用强制选项进行 proc 追加,以便在数据不匹配时具有空值(不推荐)。

  3. 创建 table 而不是插入(可以使用 datastep 或 proc append 完成)dbcreate_table_opts 选项用于为 Teradata 创建适当的主索引 table .

第1点更可取

     proc sql;
    create table teralib.staging_customer_ref
    (FastLoad=YES dbcreate_table_opts= 'primaryindex(cust_number)') as
   select * from saslib.cust_ref;
   quit;