Using SAS Macro to pipe a list of filenames from a Windows directory

前端 未结 8 2203
独厮守ぢ
独厮守ぢ 2020-12-03 12:13

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

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 12:59

    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.

提交回复
热议问题