<?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: macro quoting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/416015#M102131</link>
    <description>&lt;P&gt;I think the original question:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;How can&amp;nbsp;I avoid the "%" to be interpreted as a macro identifier?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;is good to answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, %NRBQUOTE does not prevent macro triggers from resolving (despite what one might expect from it's name).&amp;nbsp; For that, you need to use %SUPERQ.&amp;nbsp; I have yet to find a use for %NRBQUOTE.&amp;nbsp; I think a complete package of macro quoting functions is %STR, %NRSTR, %BQUOTE, %SUPERQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
  %local i ;
  data _NULL_ ;
    %do i=1 %to %sysfunc(countw(%superq(lst_a),¤)) ;
      put "%scan(%superq(lst_a),&amp;amp;i.,¤) - %scan(%superq(lst_b),&amp;amp;i.,¤)" ;
    %end ;
  run ;
%mend test ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log is:&lt;/P&gt;
&lt;PRE&gt;MPRINT(TEST):   data _NULL_ ;
MPRINT(TEST):   put "+10% - AAA" ;
MPRINT(TEST):   put "-8% - BBB" ;
MPRINT(TEST):   run ;

+10% - AAA
-8% - BBB
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Key changes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I used %SUPERQ instead of %BQUOTE&lt;/LI&gt;
&lt;LI&gt;I added %SUPERQ inside the COUNTW(), where there was no macro quoting&lt;/LI&gt;
&lt;LI&gt;I specified&amp;nbsp;the delimiter to COUNTW(),&amp;nbsp;to match the delimiter that was specified&amp;nbsp;for %SCAN (I don't know if&amp;nbsp;using that box character could be a problem at some point but it seems to work fine, usually I just use pipe)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;When you specify a delimiter for %SCAN&amp;nbsp; in the macro language, you do not need to place quote marks around the value.&amp;nbsp; The macro language knows it is a text value because everything in the macro language is text, it's not like the SAS language where quotes are needed to indicate that a literal value is text.&amp;nbsp; If you add single quote marks, they will be included as delimiters.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a side note, if you use pipe as a delimiter, you would not need macro quoting in this case at all, because macro names cannot start with a pipe.&amp;nbsp; So below works fine too:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	SELECT a, b
	INTO :lst_a SEPARATED BY '|',
	     :lst_b SEPARATED BY '|'
	FROM have;
quit;

%macro test;
  %local i ;
  data _NULL_ ;
    %do i=1 %to %sysfunc(countw(&amp;amp;lst_a,|)) ;
      put "%scan(&amp;amp;lst_a,&amp;amp;i.,|) - %scan(&amp;amp;lst_b,&amp;amp;i.,|)" ;
    %end ;
  run ;
%mend test ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 Nov 2017 13:28:11 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2017-11-24T13:28:11Z</dc:date>
    <item>
      <title>macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415843#M102057</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simplified example of the probleme i meet :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm=',';
input a $ b$;
cards;
+10%, AAA
-8%, BBB
;
run;

proc sql noprint;
	SELECT a, b
	INTO :lst_a SEPARATED BY '¤',
	     :lst_b SEPARATED BY '¤'
	FROM have;
quit;


%macro test;

	data _NULL_;
	    %do i=1 %to %sysfunc(countw(&amp;amp;lst_a.));
			put "%scan(%nrbquote(&amp;amp;lst_a.),&amp;amp;i.,'¤') - %scan(%nrbquote(&amp;amp;lst_b.),&amp;amp;i.,'¤')";
		%end;
	run;

%mend test;

%test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log indicates the following errors :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ERROR: The value ¤ is not a valid SAS name.
WARNING: Apparent invocation of macro ¤ not resolved.
ERROR: The value ¤ is not a valid SAS name.
WARNING: Apparent invocation of macro ¤ not resolved.
ERROR: The value ¤ is not a valid SAS name.
WARNING: Apparent invocation of macro ¤ not resolved.
ERROR: The value ¤ is not a valid SAS name.
WARNING: Apparent invocation of macro ¤ not resolved
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are wondering what is the goal, in reality, my have dataset contains metadata for the automatic generation of datasets. There is a "label" column with certain values ending with the "%" character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can i avoid the "%" to be interpreted as a macro identifier ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 15:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415843#M102057</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-11-23T15:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415845#M102059</link>
      <description>I managed to get rid of the messages by replacing each "%" character with "%%" in the label column. Problem solved.</description>
      <pubDate>Thu, 23 Nov 2017 15:16:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415845#M102059</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-11-23T15:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415853#M102064</link>
      <description>&lt;P&gt;Sorry, sounds a bit like a broken records here, but why.&amp;nbsp; Macro is&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;not the place&lt;/STRONG&gt;&lt;/U&gt; to be doing data processing.&amp;nbsp; You have basically created mess of code to effectively do:&lt;/P&gt;
&lt;PRE&gt;data have;
  length want $200;
  infile cards dlm=',';
  input a $ b$;
  want=catx('-',a,b);
cards;
+10%, AAA
-8%, BBB
;
run;
proc print data=have;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Nov 2017 15:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415853#M102064</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-23T15:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415868#M102073</link>
      <description>&lt;P&gt;I was expecting you &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, i know what macros are and i try not to overuse them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is more precisely what i want to do :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Metadata describing datasets to be generated automatically */
data meta;
	infile cards dlm=","
	length ds $8 var $10 desc $100 len fmt infmt $5;
	input ds var desc len fmt infmt;
	cards;
Companies,name,Name of the company,$20,$20.,$20.
Companies,adress,Adress of the company,$100,$100.,$100.
;
run;

/* Now, I want to use meta to generate the companies dataset */
data companies;
	attrib /* Automatically generated formats, labels ... */
	...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Exporting the meta columns in macrovariable lists to generate the attrib command was the simplest way that came up to me but&lt;/P&gt;
&lt;P&gt;if you have a non macro simple solution, i am interested.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 16:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415868#M102073</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-11-23T16:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415873#M102076</link>
      <description>&lt;P&gt;Unless you have a proper metadata program, then a few methods spring to mind.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Have a template dataset, this can be set with your data at run time&lt;/P&gt;
&lt;P&gt;- Have a view&lt;/P&gt;
&lt;P&gt;- Have a describe table output which can generate the table at run time (&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473675.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473675.htm&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;- Use call execute&lt;/P&gt;
&lt;P&gt;Those are four that spring to mind.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 17:04:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415873#M102076</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-23T17:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415879#M102081</link>
      <description>&lt;P&gt;Using single quotes around the label values will prevent the macro processor from trying to evaluate macro triggers.&lt;/P&gt;
&lt;P&gt;If you are going to use metadata to generate code then I find it helps to name to variables in the metadata for the option they represent. Also do not blindly attach $xx formats to variables. SAS does not need them and they can cause havoc when you start combining datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data meta;
	infile cards dsd truncover ;
	length memname name $32 label $256 length $7 format informat $41;
	input memname -- informat;
cards;
Companies,name,Name of the company,$20,,
Companies,address,Address of the company,$100,,
Companier,percent,% or market,8,percent.,
;
run;
proc print; run;

filename code temp;
data _null_;
  file code ;
  set meta end=eof;
  if _n_=1 then put 'data ' memname ';' ;
  put '  attrib ' name length= @;
  if not missing(format) then put format= @;
  if not missing(informat) then put informat= @;
  if not missing(label) then do;
    label = quote(trim(label),"'");
    put label=@ ;
  end;
  put ';' ;
  if eof then put 'run;';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;2432  %include code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is file C:\Users\ABERNA~1\AppData\Local\Temp\1\SAS Temporary
      Files\_TD29228_AMRL20B7F00CGPP_\#LN00085.
2433 +data Companies ;
2434 +  attrib name length=$20 label='Name of the company' ;
2435 +  attrib address length=$100 label='Address of the company' ;
2436 +  attrib percent length=8 format=percent. label='% or market' ;
2437 +run;

NOTE: Variable name is uninitialized.
NOTE: Variable address is uninitialized.
NOTE: Variable percent is uninitialized.
NOTE: The data set WORK.COMPANIES has 1 observations and 3 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 18:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415879#M102081</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-23T18:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415950#M102109</link>
      <description>&lt;P&gt;Thanks a lot &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; for your feedback.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Our metadata table is an import from a specification file which is not under our responsibility. This specification is subject&lt;/P&gt;
&lt;P&gt;to frequent evolutions and the goal is to absorb those evolutions the more transparently possible.&lt;/P&gt;
&lt;P&gt;Using call execute or generating a temporary file as you suggest should provide us a non macro solution.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 08:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415950#M102109</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-11-24T08:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415960#M102113</link>
      <description>&lt;P&gt;Just as a word of advice, get a data specification/import document drawn up and signed off for that metadata (I know sounds daft, metadata about metadata), otherwise you will end up playing a game of what I call pin the tail on the still live donkey in the field, you may catch it unawares first and get it stuck on, but any attempt after that will take x% more effort due to a moving target.&amp;nbsp; A signed off spec gives you leverage to push budgets and such like.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 09:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415960#M102113</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-24T09:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415970#M102122</link>
      <description>&lt;P&gt;Thanks for the advice. I agree with you. We have well defined procedures where every evolution is materialized by a contract and no evolution is taken into account until agreed by all parties.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 09:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/415970#M102122</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-11-24T09:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/416015#M102131</link>
      <description>&lt;P&gt;I think the original question:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;How can&amp;nbsp;I avoid the "%" to be interpreted as a macro identifier?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;is good to answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, %NRBQUOTE does not prevent macro triggers from resolving (despite what one might expect from it's name).&amp;nbsp; For that, you need to use %SUPERQ.&amp;nbsp; I have yet to find a use for %NRBQUOTE.&amp;nbsp; I think a complete package of macro quoting functions is %STR, %NRSTR, %BQUOTE, %SUPERQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
  %local i ;
  data _NULL_ ;
    %do i=1 %to %sysfunc(countw(%superq(lst_a),¤)) ;
      put "%scan(%superq(lst_a),&amp;amp;i.,¤) - %scan(%superq(lst_b),&amp;amp;i.,¤)" ;
    %end ;
  run ;
%mend test ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log is:&lt;/P&gt;
&lt;PRE&gt;MPRINT(TEST):   data _NULL_ ;
MPRINT(TEST):   put "+10% - AAA" ;
MPRINT(TEST):   put "-8% - BBB" ;
MPRINT(TEST):   run ;

+10% - AAA
-8% - BBB
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Key changes:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I used %SUPERQ instead of %BQUOTE&lt;/LI&gt;
&lt;LI&gt;I added %SUPERQ inside the COUNTW(), where there was no macro quoting&lt;/LI&gt;
&lt;LI&gt;I specified&amp;nbsp;the delimiter to COUNTW(),&amp;nbsp;to match the delimiter that was specified&amp;nbsp;for %SCAN (I don't know if&amp;nbsp;using that box character could be a problem at some point but it seems to work fine, usually I just use pipe)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;When you specify a delimiter for %SCAN&amp;nbsp; in the macro language, you do not need to place quote marks around the value.&amp;nbsp; The macro language knows it is a text value because everything in the macro language is text, it's not like the SAS language where quotes are needed to indicate that a literal value is text.&amp;nbsp; If you add single quote marks, they will be included as delimiters.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a side note, if you use pipe as a delimiter, you would not need macro quoting in this case at all, because macro names cannot start with a pipe.&amp;nbsp; So below works fine too:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	SELECT a, b
	INTO :lst_a SEPARATED BY '|',
	     :lst_b SEPARATED BY '|'
	FROM have;
quit;

%macro test;
  %local i ;
  data _NULL_ ;
    %do i=1 %to %sysfunc(countw(&amp;amp;lst_a,|)) ;
      put "%scan(&amp;amp;lst_a,&amp;amp;i.,|) - %scan(&amp;amp;lst_b,&amp;amp;i.,|)" ;
    %end ;
  run ;
%mend test ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Nov 2017 13:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/416015#M102131</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-11-24T13:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: macro quoting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/416031#M102136</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt; for these usefull additions.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 14:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-quoting/m-p/416031#M102136</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-11-24T14:29:38Z</dc:date>
    </item>
  </channel>
</rss>

