<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: use ampersand in concatenation string but not a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955214#M373064</link>
    <description>&lt;P&gt;You'll need some macro quoting to mask the &amp;amp; so that the macro processor doesn't try to resolve the macro variable BANQUE.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error about column BANQUE not existing is because your PROC SQL step reads in get_base_url, which doesn't have the BANQUE column in it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this simple example where you have one record in both datasets, the code would work if the SQL step joins&amp;nbsp;get_base_url and&amp;nbsp;get_table_finale1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data get_base_url ;
format HTTPS $50. ;
format appli $10. ;
appli = 'GEC' ;
HTTPS = "https://gec0-kf.compagny.fr/CONSULTATION/?mnc=GEC" ;
output ;
run ;

%macro mv_calcul_url(p_appli, p_banque) ;
  %local rc url_definie ;
  %let url_definie = ;
  %let rc=%sysfunc(dosubl(%nrstr(
    proc sql noprint ;
      select
        cats(HTTPS,"%nrstr(&amp;amp;banque)=",&amp;amp;p_banque) into :url_renvoye
      from get_base_url,get_table_finale1
      where appli = "&amp;amp;p_appli" 
    ;
    quit ;
    ))) ;
	
	%superq(url_renvoye)

%mend mv_calcul_url;


data get_table_finale1 ;
banque = '14940' ;
output ;
run ;

data want_table_finale2 ;
set get_table_finale1 ;
url_gec  = "%mv_calcul_url(GEC,banque)";
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While I'm a fan of the macro language and DOSUBL, depending on the big picture, it's possible you could get what you want with just a SQL query, without the nee to build a function-style macro, e.g.:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
  create table want as
  select
    banque
   ,cats(HTTPS,"%nrstr(&amp;amp;banque)=",banque)  as url_gec
  from get_base_url,get_table_finale1
  where appli = "GEC" 
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2025 14:01:09 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2025-01-06T14:01:09Z</dc:date>
    <item>
      <title>use ampersand in concatenation string but not a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955196#M373056</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data get_base_url ;
format HTTPS $50. ;
format appli $10. ;
appli = 'GEC' ;
HTTPS = "https://gec0-kf.compagny.fr/CONSULTATION/?mnc=GEC" ;
output ;
run ;

%macro mv_calcul_url(p_appli, p_banque) ;
	%local rc url_definie ;
	%let url_definie = ;
 %let rc=%sysfunc(dosubl(%nrstr(
     proc sql noprint ;
		select
			HTTPS||"&amp;amp;banque="||&amp;amp;p_banque into :url_renvoye
		from get_base_url
		where appli = "&amp;amp;p_appli" 
		;
	quit ;
    ))) ;
	

	&amp;amp;url_renvoye ;

%mend mv_calcul_url;


data get_table_finale1 ;
banque = '14940' ;
output ;
run ;

data want_table_finale2 ;
set table_finale1 ;
url_gec  = "%mv_calcul_url(GEC,banque)";
run ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;hello&lt;/P&gt;
&lt;P&gt;i would like to get a&amp;nbsp;url_gec column that contains the string&lt;/P&gt;
&lt;P&gt;'&lt;A href="https://gec0-kf.compagny.fr/CONSULTATION/?mnc=GEC&amp;amp;banque=14940" target="_blank"&gt;https://gec0-kf.compagny.fr/CONSULTATION/?mnc=GEC&amp;amp;banque=14940&lt;/A&gt;'&lt;/P&gt;
&lt;P&gt;but the log file says that :&lt;/P&gt;
&lt;P&gt;WARNING: Apparent symbolic reference BANQUE not resolved.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: banque.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;many thanks in advance for your help&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 10:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955196#M373056</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2025-01-06T10:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: use ampersand in concatenation string but not a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955197#M373057</link>
      <description>&lt;P&gt;If you don't want an ampersand to be treated as part of the macro language, enclose it in single quotes not double quotes.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 10:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955197#M373057</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2025-01-06T10:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: use ampersand in concatenation string but not a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955214#M373064</link>
      <description>&lt;P&gt;You'll need some macro quoting to mask the &amp;amp; so that the macro processor doesn't try to resolve the macro variable BANQUE.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error about column BANQUE not existing is because your PROC SQL step reads in get_base_url, which doesn't have the BANQUE column in it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For this simple example where you have one record in both datasets, the code would work if the SQL step joins&amp;nbsp;get_base_url and&amp;nbsp;get_table_finale1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data get_base_url ;
format HTTPS $50. ;
format appli $10. ;
appli = 'GEC' ;
HTTPS = "https://gec0-kf.compagny.fr/CONSULTATION/?mnc=GEC" ;
output ;
run ;

%macro mv_calcul_url(p_appli, p_banque) ;
  %local rc url_definie ;
  %let url_definie = ;
  %let rc=%sysfunc(dosubl(%nrstr(
    proc sql noprint ;
      select
        cats(HTTPS,"%nrstr(&amp;amp;banque)=",&amp;amp;p_banque) into :url_renvoye
      from get_base_url,get_table_finale1
      where appli = "&amp;amp;p_appli" 
    ;
    quit ;
    ))) ;
	
	%superq(url_renvoye)

%mend mv_calcul_url;


data get_table_finale1 ;
banque = '14940' ;
output ;
run ;

data want_table_finale2 ;
set get_table_finale1 ;
url_gec  = "%mv_calcul_url(GEC,banque)";
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While I'm a fan of the macro language and DOSUBL, depending on the big picture, it's possible you could get what you want with just a SQL query, without the nee to build a function-style macro, e.g.:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
  create table want as
  select
    banque
   ,cats(HTTPS,"%nrstr(&amp;amp;banque)=",banque)  as url_gec
  from get_base_url,get_table_finale1
  where appli = "GEC" 
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 14:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955214#M373064</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-01-06T14:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: use ampersand in concatenation string but not a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955218#M373065</link>
      <description>&lt;P&gt;Let's work through some of your issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First if you don't want the macro processor to process the string then use single quotes not double quotes around the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'&amp;amp;banque='&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second go ahead and use the appropriate CATxxx() function instead of the plain || operator.&amp;nbsp; In your code that is important because your dataset variable HTTPS is probably padded with spaces you don't want included in your URL.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third since your example dataset does not have a variable named banque I assume you want the value passed into the P_BANQUE parameter to become part of the URL instead.&amp;nbsp; So you need quotes to make it look like string instead of a variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select cats(HTTPS,'&amp;amp;banque=',"&amp;amp;p_banque") into :url_renvoye&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fourth you do not want to include the semicolon into the result so remove that last semicolon in the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And also you will need protect the value returned by the macro.&amp;nbsp; So add a call to %SUPERQ() instead of just expanding the macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mv_calcul_url(p_appli, p_banque) ;
%local rc url ;
%let rc=%sysfunc(dosubl(%nrstr(
proc sql noprint ;
  select cats(HTTPS,'&amp;amp;banque=',"&amp;amp;p_banque")
    into :url
  from get_base_url
  where appli = "&amp;amp;p_appli" 
;
quit;
))) ;

%superq(url)

%mend mv_calcul_url;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also use the QUOTE() function to add actual quotes around the value instead by just updating the expression used in the SELECT clause.&amp;nbsp; With single quotes around the value there is no need the %SUPERQ() call.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;quote(cats(HTTPS,'&amp;amp;banque=',"&amp;amp;p_banque"),"'")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally since there is a BANQUE variable in the dataset you are using to generate the macro calls then it really looks like&amp;nbsp;the timing of your call is off.&amp;nbsp; The macro processor will call the macro while the data step is still being compiled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use the dataset variable's value when generating the call you need to wait until while the data step is actually running.&amp;nbsp; You can use RESOLVE() function for that.&amp;nbsp; Again use one of the CATxxx series of functions to generate the appropriate macro call for each observation.&amp;nbsp; Remember to use single quotes around the string with the % so the macro processor does not try to run the macro too soon.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_table_finale2 ;
  set table_finale1 ;
  url_gec  = resolve(cats('%mv_calcul_url(GEC,',banque,')');
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 14:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-ampersand-in-concatenation-string-but-not-a-macro-variable/m-p/955218#M373065</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-06T14:56:01Z</dc:date>
    </item>
  </channel>
</rss>

