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
Onyx | Level 15

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



SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 1353 views
  • 1 like
  • 3 in conversation