0

I have similar files in a specific folder. I need to run same program for every files. So I thought of using macro. But I encountered a problem.

    %macro xyz(cityname);                                                                   *IMPORTING FILE;                                                                                                                         
    proc import datafile='G:\Interns\Shiyas\'&cityname'.csv'                                                                    
    out=out.datafile                                                                                                                         
    dbms=csv replace ;                                                                                                                       
    guessingrows=200;     

/* PROGRAM */

PROC EXPORT DATA =out.hsi_area  OUTFILE = 'G:\Interns\Shiyas\SAS\Output csv files\'&cityname'\Area.csv';                                  
PROC EXPORT DATA =out.hsi_age  OUTFILE = 'G:\Interns\Shiyas\SAS\Output csv files\'&cityname'\Age.csv';  

%mend; 

%xyz(bangalore);
%xyz(chennai);
%xyz(delhi);
%xyz(kochi);

I know this is not the right format to call macro into a filename. But it would really helpful if I could call the argument to the filename. How can we do it?

Abdul Shiyas
  • 401
  • 3
  • 9
  • 30

1 Answers1

1

Macros cannot be resolved between single quotation marks.

You should rewrite it as

"G:\Interns\Shiyas\&cityname..csv"

The double period is needed because the first is used for the macro resolution.

Check out this link

Matt
  • 171
  • 10