Hi all,
Let me briefly describe the problem and what I want to do.
I have 32 data files in a directory. Normally, I just import one by one, but now I want to write a macro to import them all into a library. All these 32 files have different names, of course, but they have 2 common things: TFO at the front, and OUT at the end. For example, tfo.address_type.out, or tfo_country.out. My idea for the macro is that I put the middle parts of the names of these files into a macro variable called "filenames", then I use the %SCAN macro function to extract the MIDDLE parts of those names. So, I put in this piece of codes:
proc import datafile="C:\MF\Quarterly_Full_History\tfo.%scan(&filenames, &filecount).out"
To my surprise, the log windows always warns that it cannot find the physical file, i.e. the %SCAN macro function doesn't work. BUT it doesn't work in a way that doesn't make sense to me. It looks like below:
MPRINT(IMPORT_TFO): proc import datafile="C:\MF\Quarterly_Full_History\tfo..out" out=mf.tfo_
dbms=dlm replace;
MPRINT(IMPORT_TFO): ADLM;
MPRINT(IMPORT_TFO): delimiter='|';
MPRINT(IMPORT_TFO): getnames=no;
MPRINT(IMPORT_TFO): run;
ERROR: Physical file does not exist, C:\MF\Quarterly_Full_History\tfo..out.
And this is NOT what I thought of as why the error came, i.e. %macro function inside double quotes that treat everything inside as merely characters, because otherwise I would expect to see the full fragment "%scan(&filenames, &filecount) not resolved and treated as nothing like a string of characters. What's more, the %SCAN function inside the double quotes doesn't have the usual blue color font (syntax highlighting), so it doesn't work.
Could you please help? Sorry if my question is not clear or so. I have used SAS for almost 1 year now, but only have begun to learn to use macro just recently.
Thank you so much
Message was edited by: smilingmelbourne