BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
havmaage
Obsidian | Level 7

Hi 

I am trying to add '% before and at the end of a macro variable 

it does the job but i cannot avoid the warning. 

 

it seems that it has something to do with the % that sas try to resolve in a certain way. 

 

my code 

 

%MACRO squote(value);
	%unquote(%str(%')%qsysfunc(tranwrd(%superq(value),%str(%'),''))%str(%'))
%MEND squote;

%MACRO GET_VIEWS(TABLENAME);

	DATA _NULL_;
		CALL SYMPUTX ('TABLE', &TABLENAME);
 	RUN;

	%PUT table=&TABLE;
	%LET TEST=%squote(%SYSFUNC(CAT(%,&TABLE,%)));
	%PUT TEST=&TEST;

%MEND;

%GET_VIEWS('MYTABLE');

Is there a way to escape  % and single quotes and add them dynamically 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You are overcomplicating this. It is quite easy to "mask" this in a data step by building a string from pieces:

%macro get_views(tablename);
data _null_;
call symputx('table',"'%"!!"&tablename."!!"%'",'g');
run;
%put &=table;
%mend;
%get_views(MYTABLE)

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

You are overcomplicating this. It is quite easy to "mask" this in a data step by building a string from pieces:

%macro get_views(tablename);
data _null_;
call symputx('table',"'%"!!"&tablename."!!"%'",'g');
run;
%put &=table;
%mend;
%get_views(MYTABLE)
yabwon
Amethyst | Level 16

Hi,

 

You already have the answer for your question, but I'm just guessing that you want to get something like "dynamic like condition"  in where clause? If yes, you could do it also like that:

%let table=CLASS;

proc sql;
  select * from dictionary.tables
  where memname like '%'!!"&table"!!'%'
  ;
quit;

 

All the best

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1762 views
  • 1 like
  • 3 in conversation