使用 sql 单引号值创建宏变量 [英] single quoting values using sql to create macro variable
问题描述
我在 SAS 中使用宏来循环特定库中的数据表.我将元数据信息放在 data null 步骤中,并与 where 语句和我的宏变量进行比较.
I am using a macro in SAS to loop over the data tables in a specific library. I put the metadata information in a data null step and make a comparison with a where statement and my macro variable.
我的 SQL 步骤如下所示:
My SQL step looks like:
proc sql;
select quote(trim(code)) into :procedures separated by ', ' from procedures;
quit;
code
的某些值包含45.10"和G0102"等值,因此不能强制转换为数字.宏包含以下行:
Some values of code
contain values like "45.10" and "G0102", so cannot be coerced to numeric. The macro contains the line:
%macro filter_codes(indata, outdata);
data &outdata;
set &indata(where = (code in (&procedures)));
run;
%mend;
但是当使用quote"函数进行双引号时,十进制值会产生问题.
but the decimal values create an issue when double-quoted using the "quote" function.
我可以用单引号分隔值吗?
Can I separate values with single quotes?
问题是由于 filter_codes 宏在调用执行步骤中运行(在一系列数据集上)并且在双引号内的宏变量中解析的双引号将结束调用执行.
The issue was caused by the fact that the filter_codes macro was run within a call execute step (over a range of datasets) and double quotes resolved in macro variables inside of double quotes would end the call execute.
推荐答案
试试这个:
proc sql;
select catt("'", code, "'") into :procedures separated by ', ' from procedures;
quit;
同时修复 set 语句中的 where 选项:
Also fix the where option in set statement:
set &indata(where=(code in (&procedures)));
这篇关于使用 sql 单引号值创建宏变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!