linux - 在 sas 文件名管道中未解析宏的明显调用

标签 linux sas pipe sas-macro

我正在使用以下 SAS 代码查找目录 &directory. 下的所有文件及其大小。

filename tmp pipe "find &directory. -type f -printf '%p %s\n'";
data all_files;
  infile tmp;
  length file_path $255. size 8.;
  input file_path size;
run;

虽然输出数据tmp是我想要的,但代码会给我警告。

WARNING: Apparent invocation of macro S not resolved.

我试过在“%”之前添加一个额外的“%”,即

filename tmp pipe "find &directory. -type f -printf '%%p %%s\n'"

但它不起作用。

我怎样才能摆脱警告?谢谢。


我也试过 %str%nrstr,

filename tmp pipe %str("find &directory. -type f -printf '%p %s\n'");
filename tmp pipe %nrstr("find &directory. -type f -printf '%p %s\n'");
filename tmp pipe %str("find &directory. -type f -printf '%%p %%s\n'");
filename tmp pipe %nrstr("find &directory. -type f -printf '%%p %%s\n'");
filename tmp pipe "find &directory. -type f -printf '%str(%%)p %str(%%)s\n'");
filename tmp pipe "find &directory. -type f -printf '%nrstr(%%)p %nrstr(%%)s\n'");

他们都没有解决问题。

最佳答案

宏处理器将在双引号括起来的字符串中查找宏触发器 &%,但不会在单引号括起来的字符串中查找。您可以使用 quote() 函数将字符串括在单引号中。

%let cmd=find &directory/ -type f -printf '%s %p\n' ;
filename tmp pipe %sysfunc(quote(&cmd,%str(%')));

或者您可以只使用 SAS 代码,避免让宏处理器介入。

您可以使用数据步来调用 FILENAME() 函数,而不是创建 FILENAME 语句。

data _null_;
  rc=filename('TMP'
     ,catx(' ',"find &directory/ -type f -printf",quote('%s %p\n',"'"))
     ,'PIPE');
  put rc= ;
run;
data all_files;
  infile tmp truncover;
  input size file_path $255. ;
run;

或者您根本无法创建文件引用,而只是在 INFILE 语句中使用 FILEVAR= 选项来传递命令。

data all_files;
  length cmd $200;
  cmd = catx(' ',"find &directory/ -type f -printf",quote('%s %p\n',"'"));
  infile tmp pipe filevar=cmd truncover;
  input size file_path $255. ;
run;

注意:颠倒 printf 字符串中大小和路径的顺序将避免在文件名包含嵌入空格时解析结果时出现问题。

关于linux - 在 sas 文件名管道中未解析宏的明显调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54338636/

相关文章:

c - 无法从与共享库链接的 C 程序访问全局程序集标签数​​据

sas - 如何在 MAC 上读取/转换 SAS Gov't Data 文件?

sockets - 我应该在哪个时刻使用哪种进程间通信(ipc)机制?

python - 如何解析并附加到 flexget yaml 配置文件?

linux - CentOS 上的 Apache 问题配置路由到 "Index.html"(大写“I”)

c - 僵尸进程在其父进程死亡后去了哪里?

sas - 如何更简单地转置数据集

c# - 在 ASP .NET Visual Studio 中使用 SAS 存储过程。 SAS 集成技术?

在 UNIX 中创建 FIFO

R:使用管道 %>% 和 pkg::fo 会导致错误 "Error in .::base : unused argument"