【问题标题】:SAS Multiple importSAS 多重导入
【发布时间】:2018-09-26 16:51:14
【问题描述】:

有没有一种方法可以在 SAS 中对 excel 电子表格进行多过程导入?见下文。我想做类似的事情:*.xlsx。

    proc import datafile= "/gpfs_nonhsm02/corrections/users/id/CB10/IMPORT1/BANK053.xlsx" dbms=xlsx out=OUT.IMPORT_DS4 replace;
    sheet="CIG OPT OUT";
    getnames=YES;
run;


proc import datafile= "/gpfs_nonhsm02/corrections/users/id/CB10/IMPORT1/BANK111.xlsx" dbms=xlsx out=OUT.IMPORT_DS5 replace;
    sheet="CIG OPT OUT";
    getnames=YES;
run;



proc import datafile= "/gpfs_nonhsm02/corrections/users/id/CB10/IMPORT1/BANK121.xlsx" dbms=xlsx out=OUT.IMPORT_DS6 replace;
    sheet="CIG OPT OUT";
    getnames=YES;
run;

【问题讨论】:

    标签: import sas proc


    【解决方案1】:

    使用 LIBNAME 代替 PROC COPY。

    libname myXLSX XLSX "/gpfs_nonhsm02/corrections/users/id/CB10/IMPORT1/BANK111.xlsx";
    
    proc copy in=myXLSX out=WORK;
    select <list of data sets here>;
    run;
    

    【讨论】:

      【解决方案2】:

      txt 中的导入可以使用 *,但对于 .xlsx,您可以使用宏功能。下面是一个例子,希望对你有帮助。 我创建了两个示例。

      示例一

      /* function for the import of specific tables. */
      %macro manytables(table, out);
          proc import datafile= "\gpfs_nonhsm02\corrections\users\id\CB10\IMPORT1\&table..xlsx" dbms=xlsx out=&out. replace;
              sheet="CIG OPT OUT";
              getnames=YES;
          run;
      %mend;
      %manytables(BANK053, IMPORT_DS4);
      %manytables(BANK111, IMPORT_DS5);
      %manytables(BANK121, IMPORT_DS6);
      

      示例二。 按数字顺序导入所有目录。

      /* initializing the variable */
      %let BD = 0;
      
      /* function that read your tables */
      %macro manytables(table, out);
          proc import datafile= "\gpfs_nonhsm02\corrections\users\id\CB10\IMPORT1\&table..xlsx" dbms=xlsx out=&out. replace;
              sheet="CIG OPT OUT";
              getnames=YES;
          run;
      %mend;
      
      /* function that performs the import of all tables */
      %macro list;
          %do %while (&BD. < 111);
                %manytables(BANK&BD., IMPORT_DS&BD.);
               %let BD = %eval(&BD. + 1);
          %end;
      %MEND list;
      %list;
      

      祝你好运!!!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-22
        • 2023-04-08
        • 2018-03-02
        • 2019-10-12
        • 1970-01-01
        相关资源
        最近更新 更多