BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hari2
Quartz | Level 8

Hi All,

 

I have a variable in which we have value with Single Quote in it. 

Ex: ABC 'DEF.

 

When I find for this like within a dataset,

 

data abc;

set abcd;

where col1 = 'ABC 'DEF';

run;

 

 It is giving error as ' Where clause operator requires Compatible variables' And here Col1 is a Character Variable. 

 

Please suggest your inputs.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Use double quotes?

 

data abcd;
col1="ABC 'DEF";output;
col1="ABCABC";output;
run;

data abc;
    set abcd;
    where col1="ABC 'DEF";
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Use double quotes?

 

data abcd;
col1="ABC 'DEF";output;
col1="ABCABC";output;
run;

data abc;
    set abcd;
    where col1="ABC 'DEF";
run;
ballardw
Super User

Another approach that you should be aware of is doubling the quote character where needed.

 

data abcd;
col1="ABC 'DEF";output;
col1="ABCABC";output;
run;

data abc;
    set abcd;
    where col1='ABC ''DEF';
run;

The quote in blue is two single quotes.

You will want to know this because if you manage to acquire a string with both single and double quote marks then you would still have the issue. Consider searching for something like 5' 8" . Then either '5' 8"' or "5' 8"" will have a problem. The two quotes together are the solution in that case:

data abcd;
col1="ABC 'DEF";output;
col1="ABCABC";output;
col1="5'12""";output;
run;

data abc;
    set abcd;
    where col1="5'12""";;
run;

Look at the abcd set to verify that there is only one double quote in the last value.

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 478 views
  • 1 like
  • 3 in conversation