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

前端 未结 8 2185
独厮守ぢ
独厮守ぢ 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 13:07

    We use this little macro

    %macro getdir(dir=,redirect=, switch=);
        options noxwait xsync;
        %if %length(&switch)=0 %then %let switch=b;
        data _null_; 
          xcmd='dir "' || "&dir" || '"' || "/&switch " || ">" || "&redirect";
          put 'generated the following command: ' xcmd=; 
          rc=system(xcmd);
          put 'result code of above command: ' rc=;
        run;
    %mend getdir;
    

    Sample Call

    %getdir(dir=c:\temp\,redirect=c:\temp\dir.txt) *run;
    

    If you run in batch and don't have the option noxwait xsync the job will hang on the server waiting for an operator response.

提交回复
热议问题