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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1769 views
  • 3 likes
  • 3 in conversation