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

Hi All:

What's the syntax for an if-then statement where my 'if' variable is character and the value has quotes in it. For example:

The client name is originally Joe "Average" Smith but I want to change it to Joe A Smith...

if last_name="Joe"Average"Smith" then last_name="Joe A Smith";

won't work

because 'the meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white spaced between a quoted string and the succeeding identifier is recommended.

My quotes are balanced...

1 ACCEPTED SOLUTION

Accepted Solutions
RichardinOz
Quartz | Level 8

Either double up the quotes in the centre or alternate single and double

if last_name="Joe""Average""Smith" then last_name="Joe A Smith";

if last_name='Joe"Average"Smith' then last_name="Joe A Smith";


Richard

View solution in original post

4 REPLIES 4
RichardinOz
Quartz | Level 8

Either double up the quotes in the centre or alternate single and double

if last_name="Joe""Average""Smith" then last_name="Joe A Smith";

if last_name='Joe"Average"Smith' then last_name="Joe A Smith";


Richard

art297
Opal | Level 21

The following approach might be more generalizable:

data have (drop=x y);

  informat last_name x y $50.;

  infile cards dlm='"' truncover;

  input last_name x y;

  if length(strip(x)) gt 1 then last_name=cat(strip(last_name),

    ' ',substr(x,1,1),'. ',strip(y));

  cards;

Joe"Average"Smith

Mary Jones

Tom"Tall"Jones

;

Maisha_Huq
Quartz | Level 8

Thanks Richard and Arthur!!

RichardinOz
Quartz | Level 8

I am hoping that the examples you gave are made up for the purpose of understanding quoting, and not representative of real data in one of your databases.  If the data is real I believe it would be wrong to create a middle initial based on what appears to be a nickname, and I would hesitate to remove the information inside the quotes entirely.  The best solution would be to create a nickname column and move the data in quotes to the new column.  I can suggest code if required.

Richard

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 733 views
  • 3 likes
  • 3 in conversation