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