SAS中不匹配的引号问题 [英] Unmatched quotation mark issue in SAS

查看:16
本文介绍了SAS中不匹配的引号问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As is known to all, SAS needs special care to quotation marks inside a sentence.

例如

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

提交时遇到错误.

实际上我需要将数据从另一个数据集复制到一个数据集,其中有很多包含引号的记录.赋值时,发生错误,数据步停止执行,导致其余代码无效.所以在这种情况下,不可能通过添加重复的引号来修改原始数据集,这是没有意义的.

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?

谢谢,

推荐答案

在使用宏语言(包括 %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.

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

干杯抢

这篇关于SAS中不匹配的引号问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆