sas中的sql多速率宏

5m1hhzi4  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(440)

实际上,我正试图为下面的代码创建一个宏,因此在proc sql中,我不需要创建两个不同的代码,因为它是从proc import中提取的,并在proc sql中创建两个数据集,
任何帮助都将不胜感激:)

%macro import(market);

FILENAME REFFILE "PLANNING\BASE_PORTFOLIO\BS_PORT/Test/&market..csv";

PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=&market. 
(KEEP= a b c)

REPLACE; 
/*GETNAMES=YES;*/
RUN;

%mend import;

%import (InputFile1);
%import (InputFile2);

PROC SQL;
   CREATE TABLE Outfile1 AS 
   SELECT a,b,c         
      FROM &market. t1 /*INPUT FILE READ VM*/
     GROUP BY a,b,c,
QUIT;

PROC SQL;
   CREATE TABLE Outfile2 AS 
   SELECT a,b,c         
      FROM &market. t1 /*INPUT FILE READ VM*/
     GROUP BY a,b,c,
QUIT;
soat7uwm

soat7uwm1#

market 是只存在于宏本身中的局部宏变量。添加 out 参数,并将sql语句放在宏中。

%macro import(market, out);

    FILENAME REFFILE "PLANNING\BASE_PORTFOLIO\BS_PORT/Test/&market..csv";

    PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=&market. (KEEP= a b c)
        REPLACE; 
        GETNAMES=YES;
    RUN;

    PROC SQL; CREATE TABLE &out. AS 
        SELECT a,b,c
        FROM &market. t1 
        ;
    quit;

%mend import;

%import (InputFile1, Outfile1); 
%import (InputFile2, Outfile2);

相关问题