Unmatched quotation mark issue in SAS

柔情痞子 提交于 2019-12-01 22:19:00

问题


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="&quoted";
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,


回答1:


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;

Cheers Rob




回答2:


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=&quoted;
run;


来源:https://stackoverflow.com/questions/5944628/unmatched-quotation-mark-issue-in-sas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!