using quotes in sas macro filename pipe

2019-02-20 14:31发布

I am using the following Macro that uses filename pipe. But get an error saying invalid option name "dir", etc. I suspect it could be due to the quotes while defining filename and pipe. I guess it recognizes it as an option. I tried to remove the quote, removing %bquote and having just the double quote, but still keep getting the errors.

I am using Windows, but will also be running it remotely on Linux. Any thoughts would be deeply appreciated.

%macro setprogvar(dateval);
  %global date;

  %let date=&dateval;

  %put &date;
  %put &dateval;

  %let filepath = %bquote("C:\Research\SASDataSets\bulk all data &date");

  filename CDR_Bulk pipe "dir &filepath /a:-d-h-s /b /s";

%mend setprogvar;

%setprogvar(20100331);

***LOG************
1      filename CDR_Bulk pipe "dir &filepath /a:-d-h-s /b /s";
                           ---
                           23
ERROR 23-2: Invalid option name dir.

1   !  filename CDR_Bulk pipe "dir &filepath /a:-d-h-s /b /s";
                                          -
                                          23
ERROR 23-2: Invalid option name a.

2条回答
一纸荒年 Trace。
2楼-- · 2019-02-20 14:44

The filepath Macro variable needs wrapping in double-quotes as it contains spaces. But as your string is double-quoted, you need double-double-quotes...

filename CDR_Bulk pipe "dir ""&filepath"" /a:-d-h-s /b /s";
查看更多
走好不送
3楼-- · 2019-02-20 14:50

Try changing %bquote in your macro to %str().

%Str() works during macro compile time, and should mask the double quote marks.

HTH

查看更多
登录 后发表回答