使用宏函数的 SAS 类型问题 [英] SAS type issue using a macro function

查看:27
本文介绍了使用宏函数的 SAS 类型问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宏函数定义如下.

I have a macro function defined as below.

%macro sqlloop(event_id, empl_nbr_var, fleet, base, position);
...lots of code...
%mend;

实际代码将基于更大的表进行引用,但为了排除故障和简单起见,我只使用了该表第一行 row1 的缩短版本.

the actual code will be referencing based on a bigger table, but for troubleshooting and simplicity I have a shortened version of just the first row of this table, row1.

<头>
event_idempl_nbr_var舰队基础位置
1234111320CHSA

在输出数据中检查除event_id之外的所有字符类型,它是数字.这正是我想要的程序.当我手动输入时,它完美无缺.

checking this in output data all of the types of Character except event_id, which is numeric. This is exactly what I want for the program. when I manually type in this, it works perfectly.

%sqlloop(1234, '111', '320', 'CHS', 'A');

然而,以下代码引发了各种错误,原因是我认为是类型问题.

however the following code throws all kinds of errors, stemming from what I think is a type issue.

data _null_;
    set Work.row1;
    call execute('%sqlloop(17,'||strip(empl_nbr_var)||','||strip(fleet)||','||strip(base)||','||strip(position)||');');
run;

暂时忽略第 17 部分,假设正确

我得到的第一个错误如下,所有其他错误似乎都源于未创建该表.

The first error I get is below, and all other errors seem to stem from that table not being created.

ERROR: The following columns were not found in the contributing tables: A, CHS.

注意 A 或 CHS 周围没有引号,我认为应该有引号?SAS 还是新手,所以不太熟悉,但对我来说,这似乎是错误.这对 strip() 有什么奇怪的,还是我完全遗漏的其他东西?

note that there is no quotes around A or CHS, which I believe there should be? Still new to SAS so the not super familiar but to me it looks like that is the error. Is this something weird with strip(), or something else im missing entirely?

推荐答案

对于宏处理器来说,一切都是文本.因此,在您的手动调用中,您在宏参数的值中包含了引号.而在 CALL EXECUTE() 语句中你没有.

To the macro processor everything is text. So in your manual call you have included quotes in the values of the macro parameters. And in the CALL EXECUTE() statement you did not.

您可以重新编写宏以不需要值中的引号.例如,将 &fleet. 之类的引用替换为 "&fleet.".

You can either re-write the macro to not require the quotes in the values. For example replace references like &fleet. with "&fleet.".

或者在生成宏调用时添加引号.

Or add the quote when generating the macro call.

data _null_;
  set work.row1;
  call execute(cats('%sqlloop(17,',quote(trim((empl_nbr_var))
                   ,',',quote(trim(fleet))
                   ,',',quote(trim(base))
                   ,',',quote(trim(position))
                   ,');'
  ));
run;

这篇关于使用宏函数的 SAS 类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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