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