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

查看:446
本文介绍了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天全站免登陆