BookmarkSubscribeRSS Feed
Liliya95
Fluorite | Level 6

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,",&quot));
%put decodedata1=&decodedata1;
%mend example;


%example();

 

 and when write

%let decodedata1=%sysfunc(tranwrd(&decodedata,' " ',&quot));

 

get the original string in response. What's wrong?

4 REPLIES 4
andreas_lds
Jade | Level 19

Posting log with options symbolgen mprint and mlogic activated will show what happened.

 

From the code you posted:

  • the variable &quot is undefined
  • in macro-code an empty string is %str( )
Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Astounding
PROC Star

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 937 views
  • 0 likes
  • 5 in conversation