我想在SAS EG服务器中输出我的变量,
变量"head“是"2022-02”。
但是,当我在下面运行查询时,它会生成"2020“,我怀疑它会处理公式2022-2=2020。我试着使用%b引号(‘&head.’)&会弹出错误。我不知道如何从变量"head“输出变量值为"2022-02”的列。
变量:
%put head = &head.
head = 2022-02第一次尝试:
proc sql;
create table mart_base as
select *, &head. as test2
from cr_card_acct_plan_seg_cycle
;quit;它输出列test2的"2020“
第二次尝试:
proc sql;
create table mart_base as
select *, &head. as test2, %bquote('&head.') as test1
from cr_card_acct_plan_seg_cycle
;quit;日志如下
GOPTIONS ACCESSIBLE;
24 proc sql;
25 create table mart_base as
22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?,
AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, LEN, LENGTH,
LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.
26 select *, &head. as test2, %bquote('&head.') as test1
NOTE: Line generated by the macro function "BQUOTE".
26 '2022-02'
_
22
_
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, (, *, +, -, BTRIM, CALCULATED, CASE, EXISTS, INPUT, NOT, PUT, SUBSTRING, TRANSLATE, USER, ^, ~.
ERROR 200-322: The symbol is not recognized and will be ignored.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
27 from cr_card_acct_plan_seg_cycle
28 ;如何输出具有正确的变量"head“格式的列,即2022-02?
发布于 2022-03-23 10:20:56
你有两种可能性:宣布头部为:
%let head = '2022-02'或者用代码中的变量来修饰:
proc sql;
create table mart_base as
select *, "&head." as test2
from cr_card_acct_plan_seg_cycle;
quit;发布于 2022-03-23 13:22:04
%BQUOTE()宏函数添加的宏引用混淆了SAS处理器,因此它无法识别字符串文本。
只需使用双引号而不是单引号,以使宏处理器将解析宏变量引用。
"&head"如果您确实出于某种原因需要使用单引号,则可以使用%unquote()来删除使SAS处理器混淆的宏引用。
%unquote(%bquote('&head'))或者使用%SYSFUNC()宏函数调用SAS引号()函数来添加单引号。
%sysfunc(quote(&head,%str(%')))https://stackoverflow.com/questions/71585173
复制相似问题