SAS 中不匹配的引号问题
众所周知,SAS需要特别注意句子中的引号。
例如
%let quoted="I'd like to";
data temp;
set temp;
quoted=""ed";
run;
提交时遇到错误。
事实上,我需要将数据从另一个数据集中复制到一个数据集中,其中有很多包含引号的记录。赋值时发生错误,数据步停止执行,导致其余代码无效。所以在这种情况下,不可能通过添加重复的引号来修改原始数据集,这是没有意义的。
因此,不必添加重复的错误,例如“我愿意”,还有其他方法可以避免错误,或者使数据步骤继续执行吗?
谢谢,
As is known to all, SAS needs special care to quotation marks inside a sentence.
E.g.
%let quoted="I'd like to";
data temp;
set temp;
quoted=""ed";
run;
error is encounterred when submitting.
In fact I need to copy data to one dataset from another one, in which there are a lot of records containing quotation marks. When assigning, error occurrs and data step stop executing, causing rest of the code to be invalid. So in this case, it's impossible to modify original data set by adding duplicated quotation marks, which doesn't make sense.
So instead of having to add a duplicated one, like, "I''d like to", is there any other way of avoiding the error, or making data step keeping executing?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用宏语言(包括 %let 命令)时,您不希望使用引号来标识文本字符串。要在字符串中放置单引号,您必须使用宏实用程序屏蔽函数之一,例如 %str()。使用 %let 在宏变量中放置不匹配的单引号的正确语法如下所示。单引号之前的 % 符号是转义字符,用于告诉 SAS 接下来的字符(单引号)应用作文字。另请注意,我已从 %let 中删除了双引号,因为它们不是必需的。
干杯
抢
When using the macro language (including the %let command) you do not want to use quotes to identify text strings. To place a single quote in a string you must use one of the macro utility masking functions such as %str(). The correct syntax to place a single unmatched quote in a macro variable using %let is shown below. The % symbol before the single quote is an escape character to tell SAS that the following character (a single quote) should be used as a literal. Also note that I've removed the double quotes from the %let as they are not required.
Cheers
Rob
我不确定您在实际情况下想要实现什么,但在上述情况下,可以通过删除数据步骤中的双引号来解决。
I'm not sure what you're trying to achieve in the actual situation, but in the above situation it can be solved removing the double quotation marks in the data step.