I need to replace the characters with others, but when write this, code don't work
%macro example();
%let decodedata=f"eif";
%put decodedata=&decodedata;
%let decodedata1=%sysfunc(tranwrd(&decodedata,","));
%put decodedata1=&decodedata1;
%mend example;
%example();
and when write
%let decodedata1=%sysfunc(tranwrd(&decodedata,' " ',"));
get the original string in response. What's wrong?
Posting log with options symbolgen mprint and mlogic activated will show what happened.
From the code you posted:
Look at the log, the macro fails because of the unbalanced double quote, and the single %let fails because of the undefined symbol quot. Note that " is something that works in HTML, but not as some kind of tag in SAS.
What are you trying to achieve? With complicated replacements involving quotes, I'd do it in a data step with symget() and call symputx(). Using data step functions in data steps is always easier and more transparent.
Why are you doing data manipulation in SAS Macro when there is a fully fledged language for such a purpose called base SAS? You are setting yourself up for bad unstable coding.
This is untested but should work. Change this:
&decodedata,",
Use this instead:
%bquote(&decodedata),%str(%"),
If it's possible, I do agree with the others that claim you would be well-served by switching to SAS language instead of macro language.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.