%macro EM(cntry=);
%let cntr = %sysfunc(compress(&cntry.));
%put cntry resolves to &cntry ;
%if "&cntry."="OMAN" or "&cntry." = "CHINA" %then %let like_cntry=%nrbquote('&cntry.%');
%else %let like_cntry=%nrquote('%')||%bquote('&cntry.')||%nrquote('%') ;
%put like_cntry resolves to &like_cntry.;
%mend
%em(cntry=japan)Hi,
I want to resolve &like_cntry as '%japan%' since iam using in where clause
when i was trying to resolve iam getting this output '%'||'japan'||'%'
Can anyone help me on this?
To concatenate macro variables you cant use '||' (nor '!!').
In order to dislay the &cntry value you must use double quotes.
Check next code:
%macro EM(cntry=);
%let cntr = %sysfunc(compress(&cntry.));
%put cntry resolves to &cntry ;
%if "&cntry."="OMAN" or "&cntry." = "CHINA"
%then %let like_cntry=%nrbquote("&cntry.%");
%else %let like_cntry=%nrbquote(%)&cntry.%nrbquote(%);
%put like_cntry resolves to &like_cntry.;
%mend;
%em(cntry=OMAN);
%em(cntry=japan);
To concatenate macro variables you cant use '||' (nor '!!').
In order to dislay the &cntry value you must use double quotes.
Check next code:
%macro EM(cntry=);
%let cntr = %sysfunc(compress(&cntry.));
%put cntry resolves to &cntry ;
%if "&cntry."="OMAN" or "&cntry." = "CHINA"
%then %let like_cntry=%nrbquote("&cntry.%");
%else %let like_cntry=%nrbquote(%)&cntry.%nrbquote(%);
%put like_cntry resolves to &like_cntry.;
%mend;
%em(cntry=OMAN);
%em(cntry=japan);
t can be even more simple - both methods were tested:
%macro EM(cntry=);
%let cntr = %sysfunc(compress(&cntry.));
%put cntry resolves to &cntry ;
%if "&cntry."="OMAN" or "&cntry." = "CHINA"
%then %let like_cntry=&cntry.%;
%else %let like_cntry=%nrbquote(%)&cntry.%; /*nrbquote(%);*/
%put like_cntry resolves to &like_cntry.;
%mend;
%em(cntry=OMAN);
%em(cntry=japan);
Hello,
What is the following instruction used for ?
%let cntr = %sysfunc(compress(&cntry.));
If you want to remove leading and trailing blanks, the following will be enough :
%let cntr=&cntry.;
By using compress, you also remove blanks in the country name so "COSTA RICA", for instance, will become "COSTARICA".
Try the following code and look at the log :
data _NULL_;
call symput("cntry"," COSTA RICA ");
run;
%put ***&=cntry.***;
%let cntr = %sysfunc(compress(&cntry.));
%put ***&=cntr.***;
%let cntr2=&cntry.;
%put ***&=cntr2.***;
Note that it would not have been necessary if symputx had been used instead of symput.
%macro EM(cntry=)/minoperator mindelimiter=',';
%put cntry resolves to &cntry ;
%if %upcase(&cntry.) in OMAN,CHINA %then %let like_cntry=%bquote('&cntry.%');
%else %let like_cntry=%sysfunc(compress(%bquote('% &cntry.%'),%str( ))) ;
%put like_cntry resolves to &like_cntry.;
%mend;
%em(cntry=japan)
%em(cntry=china)
How about this one ?
To put the values of macro variables next to each other just evaluate them next to each.
&X.&Y.
If you just remove the spurious vertical bar characters from your source code then and they won't end up in the generated code.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.