DATA Step, Macro, Functions and more

Apparent symbolic reference not resolved

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Apparent symbolic reference not resolved

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.


Accepted Solutions
Solution
‎10-05-2016 04:42 PM
Super User
Posts: 5,071

Re: Apparent symbolic reference not resolved

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


All Replies
Solution
‎10-05-2016 04:42 PM
Super User
Posts: 5,071

Re: Apparent symbolic reference not resolved

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.

Contributor
Posts: 66

Re: Apparent symbolic reference not resolved

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.";
Super User
Posts: 5,071

Re: Apparent symbolic reference not resolved

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.

Super User
Posts: 17,750

Re: Apparent symbolic reference not resolved

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;
Contributor
Posts: 66

Re: Apparent symbolic reference not resolved

Thank you both. That was very clear and helpful.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 1192 views
  • 0 likes
  • 3 in conversation