如何使用 CATX 函数连接 space?
How can I concatenate a space using CATX function?
我需要将数字和字符串连接成一行,但用 space 分隔。
我尝试了 5 种方法,但没有得到想要的结果。
%LET lim1 = 113;
%LET lim2 = 166;
测试 1:
%LET linha = %SYSFUNC(CATS(De,&lim1,a,&lim2,clientes));
%PUT &linha;
输出 1:
De113a166clientes
测试 2:
%LET linha = %SYSFUNC(CATS('De ',&lim1,' a ',&lim2,' clientes'));
%PUT &linha;
输出 2(错误):
30 %LET linha = %SYSFUNC(CATS('De ',&lim1,' a ',&lim2,' clientes'));
NOTE: Line generated by the macro function "SYSFUNC".
30 'De '113' a '166' clientes'
_____ _____
49 49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
测试 3:
%LET linha = %SYSFUNC(CATX(' ','De ',&lim1,' a ',&lim2,' clientes'));
%PUT &linha;
输出 3(错误):
29 %LET linha = %SYSFUNC(CATX(' ','De ',&lim1,' a ',&lim2,' clientes'));
NOTE: Line generated by the macro function "SYSFUNC".
29 'De '' '113' '' a '' '166' '' clientes'
________ ___________
49 49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
测试 4:
%LET linha = %SYSFUNC(CATX(' ',De,&lim1,a,&lim2,clientes));
%PUT &linha;
输出 4(错误):
NOTE: Line generated by the macro function "SYSFUNC".
29 De' '113' 'a' '166' 'clientes
___ ___ ___ ___
49 49 49 49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
测试 5:
%LET linha = %SYSFUNC(CATX(*,De,&lim1,a,&lim2,clientes));
%PUT &linha;
输出 5:
De*113*a*166*clientes
测试 5 非常接近我的需要,但我需要将 * 替换为空白 space。
我需要: De 113 a 166 clientes
很遗憾,我没有成功。
在宏中,您不需要使用 CAT
来组装源代码文本。
只需在所需上下文中解析宏变量即可。
%LET lim1 = 113;
%LET lim2 = 166;
%LET linha = De &lim1 a &lim2 clientes;
%PUT &=linha;
----- LOG -----
LINHA=De 113 a 166 clientes
如果在带引号的字符串或字符串值计算的 DATA 步上下文中使用宏变量值,则解析应在字符串文字的双引号内(除非宏值已经按字面意思用双引号引起来文字)
data have;
input (part1-part3) ($);
datalines;
De a clientes
Si o consumer
Mr A Sky
;
%LET lim1 = 113;
%LET lim2 = 166;
data want;
set have;
result = catx(' ', part1, "&lim1", part2, "&lim2", part3);
put result=;
run;
----- LOG -----
result=De 113 a 166 clientes
result=Si 113 o 166 consumer
result=Mr 113 A 166 Sky
我需要将数字和字符串连接成一行,但用 space 分隔。
我尝试了 5 种方法,但没有得到想要的结果。
%LET lim1 = 113;
%LET lim2 = 166;
测试 1:
%LET linha = %SYSFUNC(CATS(De,&lim1,a,&lim2,clientes));
%PUT &linha;
输出 1:
De113a166clientes
测试 2:
%LET linha = %SYSFUNC(CATS('De ',&lim1,' a ',&lim2,' clientes'));
%PUT &linha;
输出 2(错误):
30 %LET linha = %SYSFUNC(CATS('De ',&lim1,' a ',&lim2,' clientes'));
NOTE: Line generated by the macro function "SYSFUNC".
30 'De '113' a '166' clientes'
_____ _____
49 49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
测试 3:
%LET linha = %SYSFUNC(CATX(' ','De ',&lim1,' a ',&lim2,' clientes'));
%PUT &linha;
输出 3(错误):
29 %LET linha = %SYSFUNC(CATX(' ','De ',&lim1,' a ',&lim2,' clientes'));
NOTE: Line generated by the macro function "SYSFUNC".
29 'De '' '113' '' a '' '166' '' clientes'
________ ___________
49 49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
测试 4:
%LET linha = %SYSFUNC(CATX(' ',De,&lim1,a,&lim2,clientes));
%PUT &linha;
输出 4(错误):
NOTE: Line generated by the macro function "SYSFUNC".
29 De' '113' 'a' '166' 'clientes
___ ___ ___ ___
49 49 49 49
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
测试 5:
%LET linha = %SYSFUNC(CATX(*,De,&lim1,a,&lim2,clientes));
%PUT &linha;
输出 5:
De*113*a*166*clientes
测试 5 非常接近我的需要,但我需要将 * 替换为空白 space。
我需要: De 113 a 166 clientes
很遗憾,我没有成功。
在宏中,您不需要使用 CAT
来组装源代码文本。
只需在所需上下文中解析宏变量即可。
%LET lim1 = 113;
%LET lim2 = 166;
%LET linha = De &lim1 a &lim2 clientes;
%PUT &=linha;
----- LOG -----
LINHA=De 113 a 166 clientes
如果在带引号的字符串或字符串值计算的 DATA 步上下文中使用宏变量值,则解析应在字符串文字的双引号内(除非宏值已经按字面意思用双引号引起来文字)
data have;
input (part1-part3) ($);
datalines;
De a clientes
Si o consumer
Mr A Sky
;
%LET lim1 = 113;
%LET lim2 = 166;
data want;
set have;
result = catx(' ', part1, "&lim1", part2, "&lim2", part3);
put result=;
run;
----- LOG -----
result=De 113 a 166 clientes
result=Si 113 o 166 consumer
result=Mr 113 A 166 Sky