Hello friends, I want to rename a variable in macro by using filename (variable name = filename). I use the following code to import files and then use macro: /* Read datafiles in folder*/ %let subdir=C:\Users\Tri_Tri_nguyen\Desktop\Dead_final\; filename dir "&subdir.*.csv "; data new; length filename fname $ 256; infile dir eof=last filename=fname; input ; last: filename=fname; run; /* sort data and remove duplicates-*/ proc sort data=new nodupkey; by filename; run; data null; set new; call symputx(cats('filename',_n_),filename); call symputx(cats('dsn',_n_),compress(scan(filename,-2,'\.') ,'ka')); call symputx('nobs',_n_); run; %put &nobs.; %macro import; %do i=1 %to &nobs; /* Import for file No. 9 of board of directors */ proc import datafile="&&filename&i" out=dsn&i dbms=csv replace; getnames=no; run; run; .... .... data Dsn&i; set Dsn&i; rename COL1=WC&filename; /* I want to rename COL1 (in the imported file) using words "WC" and the name of the files I have imported above". For example, the imported file name is 12345, I want to rename COL1 into "wc12345". I got a lot of files like this (that is why I need a macro) */ run; ... ... %end; %mend import; %import Everything in the macro works well, except rename issue. Thank you very much for your support! Cheers, Thierry.
... View more