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

前端 未结 8 2201
独厮守ぢ
独厮守ぢ 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:54

    Make the following several changes and your code will work.

    %macro get_filenames(location);  %*--(1)--*;
       filename pipedir pipe "dir ""%unquote(&location)"" /b" lrecl=32767; %*--(2)--*;
       data filenames;
         infile pipedir truncover;
         input filename $char1000.;
         put filename=;
       run;
       filename pipedir clear;  %*--(3)--*;
    %mend;
    
    %get_filenames(d:\)          
    %get_filenames(d:\your dir)  %*--(4)--*;
    

    (1) End the %macro statement with a semi-colon;

    (2) Surround the macro variable resolution with doubled-up double quotes and %unquote;

    (3) Release the file handle by clearing it; and

    (4) Don't single quote your input parameter. macro quote instead, if necessary.

提交回复
热议问题