如何在没有特殊字符的情况下将字符串传递给宏 sas [英] how to pass a string to a macro sas without special char

查看:27
本文介绍了如何在没有特殊字符的情况下将字符串传递给宏 sas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 sas 中写了这个宏来获取一些文件的一些信息:

I wrote this macro in sas to have some information about some files :

%macro info_1(cmd);
      filename dirList pipe &cmd.;

      data work.dirList;
            infile dirList length=reclen;
            input file $varying200. reclen;
            permission=scan(file,1,"");
            if input(scan(file,2,""), 8.)=1;
            user=scan(file,3,"");
            group=scan(file,4,"");
            file_size_KB=round(input(scan(file,5,""), 8.)/1024,1);
            file_size_MB=round(input(scan(file,5,""), 8.)/1024/1024,1);
            modified_time=input(catx(" ",scan(file,6," "),scan(file,7,"")),anydtdtm.);
            date_mod = datepart(modified_time);
            time_zone=scan(file,8,"");
            file_name=scan(file,-1,"");
            format modified_time datetime19.;
            format file_size_MB comma9.;
            format date_mod date9.;
            run;

%mend info_1;

然后我声明这个宏变量:

then i declare this macro variable:

%let cmd = ls --full-time;
%let sep1= %quote( );
%let path = /data/projects/flat_file/meteo ; 
%let file = *.json ;
%let sep2 = %quote(/) ;
%let fullpath = &cmd.&sep1.&path.&sep2.&file;

然后我尝试执行宏:

%info_1(&fullpath.);

我看到了一件奇怪的事情.我发布了一张图片,因为无法描述它.我猜有特殊字符.

And i see a strange thing. I post a image because it is impossible to describe it. I guess that there are special chars.

如何解决这个问题?

推荐答案

在你的宏里面我相信你只需要在这一行加上引号:

Inside your macro I believe you just need to add quotes around this line:

filename dirList pipe &cmd.;

现在在宏解析发生后,它会像这样对待它:

Right now after the macro resolution is happening it is treating it like:

filename dirList pipe ls --full-time;

... 将 ls 部分视为文件名语句的参数.修复后,代码应显示为:

... which is treating the ls part onwards like parameters to the filename statement. When fixed the code should appear as:

filename dirList pipe "&cmd";

然后将被解析为:

filename dirList pipe "ls --full-time";

这篇关于如何在没有特殊字符的情况下将字符串传递给宏 sas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆