SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
sutzig
Fluorite | Level 6

Good evening:

 

I'm stuck creating a proc sql statement filtering for a value that includes a single quote (').

 

PROC sql;
	create table target as
	select
		*
	from 
		source
	where
		value = "Tom's Trucks"
	quit;
run;

Thanks for your help.

3 REPLIES 3
Reeza
Super User
  1. Missing semicolon to end query (in red below)
  2. SQL needs a QUIT, not a RUN (orange/purple below). Remove the RUN and leave the QUIT in and that should be good.
PROC sql;
	create table target as
	select
		*
	from 
		source
	where
		value = "Tom's Trucks" ;
	quit;
run;

@sutzig wrote:

Good evening:

 

I'm stuck creating a proc sql statement filtering for a value that includes a single quote (').

 

PROC sql;
	create table target as
	select
		*
	from 
		source
	where
		value = "Tom's Trucks"
	quit;
run;

Thanks for your help.


 

sutzig
Fluorite | Level 6

Reeza:

 

Thank you for pointing out the syntax error in the sample, but this is not the issue. The issue is creating a filter using a text value criteria which includes a single quote (and, presumably double quotes).

 

For example 

PROC sql;
	create table target as
	select
		*
	from 
		source
	where
		value in=("Tom's Trucks" ; "Carstop");
	quit;
run;

will only return records for Carstop.

 

Steve 

Tom
Super User Tom
Super User

Please provide an example of data where you are having trouble filtering.  (Note in your example you have mistakenly added an equal sign and typed a semi-colon instead of comma between the quoted list of values.)

proc sql;
create table target as
  select *
  from source
  where value in ("Tom's Trucks" , "Carstop")
;
quit;

Also since this is SQL code are you perhaps not running that WHERE clause in SAS but have actually pushed it into some remote database that has a different understanding of the meaning of double quote and single quotes?

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 930 views
  • 0 likes
  • 3 in conversation