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.
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.
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.
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.
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;
Thank you both. That was very clear and helpful.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.