SAS 中不匹配的引号问题

发布于 2024-11-06 06:04:06 字数 346 浏览 0 评论 0原文

众所周知,SAS需要特别注意句子中的引号。

例如

%let quoted="I'd like to";
data temp;
    set temp;
    quoted="&quoted";
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸠魁 2024-11-13 06:04:06

使用宏语言(包括 %let 命令)时,您不希望使用引号来标识文本字符串。要在字符串中放置单引号,您必须使用宏实用程序屏蔽函数之一,例如 %str()。使用 %let 在宏变量中放置不匹配的单引号的正确语法如下所示。单引号之前的 % 符号是转义字符,用于告诉 SAS 接下来的字符(单引号)应用作文字。另请注意,我已从 %let 中删除了双引号,因为它们不是必需的。

%let quoted=%str(I%'d like to);
data temp;    
    quoted=""ed";
run;

干杯

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.

%let quoted=%str(I%'d like to);
data temp;    
    quoted=""ed";
run;

Cheers
Rob

憧憬巴黎街头的黎明 2024-11-13 06:04:06

我不确定您在实际情况下想要实现什么,但在上述情况下,可以通过删除数据步骤中的双引号来解决。

%let quoted="I'd like to";
data temp;
    set temp;
    quoted="ed;
run;

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.

%let quoted="I'd like to";
data temp;
    set temp;
    quoted="ed;
run;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文