I am trying to amend the macro below to accept a macro parameter as the \'location\' argument for a dir command. However I cannot get it to resolve correctly due to the nes
Here's one that unscrambles the order of quoting and unquoting:
%let command =%unquote(%str(%')dir "&baseDir.data\*txt"%str(%'));
filename datain pipe &command;
where macro variable basedir can contain spaces and so can the filenames.
This combination of
%unquote and %str(%') is a frequently occuring macro idiom.
"what if I have single quote in my dir?"
Handling this situation requires a macro quoting function, such as %bquote();
Continuing the example above, this:
%let command =%unquote(%str(%')dir "%bquote(&baseDir.data\*txt)"%str(%'));
should do it.
To avoid infinite iterations of this kind of question, look at Ian Whitlock's paper, A Serious Look at Macro Quoting, which is available here;
There are (many) others, but this is the most widely cited. A little note: anything by Ian Whitlock is probably worthwhile. He writes clearly and his understanding of SAS issues is awesome.