1
votes

Actually I am trying to create a macro for below this code, so in proc sql i don't need to create separate two different codes, as its picked up from the proc import and create two datasets in proc sql,

Any help will be really appreciate :)

%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;
1

1 Answers

3
votes

market is a local macro variable that will only exist within the macro itself. Add an out parameter to the macro and place your sql statement within the macro.

%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);