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

For the following statemen in a data proc:

 

if company_name = "johnson & johnson"  then company_standardized = "Johnson & Johnson Co.";

 

It's clear what I want to do. The log says "Apparent symbolic reference not resolved", presumably looking for a macro definition when it sees the & sign. My question is, has SAS correct done what I want it to do? If not, how do I force SAS to see & as just a symbol in the string, rather than macro? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

You can clear up the problem by using single quotes instead of double quotes.  Single quotes suppress all macro activity.

 

But this particular example wouldn't cause the problem.  There would have to be a letter (not a space) immediately following the ampersand.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

You can clear up the problem by using single quotes instead of double quotes.  Single quotes suppress all macro activity.

 

But this particular example wouldn't cause the problem.  There would have to be a letter (not a space) immediately following the ampersand.

apolitical
Obsidian | Level 7
So the way to fix it is to substitute the double quotes with single quotes in that line. And what would happen if the statement is
if company_name = "johnson&johnson" then company_standardized = "Johnson & Johnson Co.";
Astounding
PROC Star

That would give you the message you received, because of the IF condition where there are letters following the &.  But if you switch to single quotes, all will be well.

Reeza
Super User

You'll get a warning, but it doesn't impact your analysis...unless you happen to have a macro variable with the same name it's looking for.

 

This won't cause any issues.

 

if company_name = 'johnson&johnson' then company_standardized = 'Johnson & Johnson Co.';

 This could happen...

%let johnson=WRONG_ANSWER;

data test;
length company_standardized_wrong company_standardized_correct $100.;
company_name = 'johnson&johnson';

if company_name = "johnson&johnson" then company_standardized_wrong = "Johnson & Johnson Co.";
else company_standardized_wrong="johnson&johnson";

if company_name = 'johnson&johnson' then company_standardized_correct = "Johnson & Johnson Co.";
else company_standardized_correct='WRONG';
run;
apolitical
Obsidian | Level 7

Thank you both. That was very clear and helpful.

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
  • 5 replies
  • 13030 views
  • 0 likes
  • 3 in conversation