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
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)
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)
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
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!
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.