<?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: Unquoting a Macro variable in a Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429253#M106012</link>
    <description>&lt;P&gt;It's all good. No big words like apologies needed. Makes mistakes to learn and share here. I was dumb 3 years ago when i wrote my first real code lol&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jan 2018 19:34:52 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-19T19:34:52Z</dc:date>
    <item>
      <title>Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429229#M106004</link>
      <description>&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hello, I'm trying to enter in a macro with a variable that normally has commas and trying to come up with a macro that can use it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; subjects&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	do subject_id &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to &lt;SPAN class="token number"&gt;8&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
		output&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	end&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;surveyselect&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;subjects groups&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; reps&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; noprint
    out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;randomizer&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;groupId&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;reader&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, I want to create a macro variable that contains 2,2,2,2&lt;/P&gt;&lt;P&gt;Here is what I came up with after discovering %unquote&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; m&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;

			&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;surveyselect&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;subjects groups&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%unquote&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; reps&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; noprint
			    out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;randomizer&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;groupId&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;reader&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
			&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; m&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%m&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"2,2,2,2"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Am I using %unquote incorrectly or is there another way to perform this?&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429229#M106004</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-19T19:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429233#M106005</link>
      <description>&lt;P&gt;I would think of using keyword parameter as opposed to positional to make it easy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="  language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrobound"&gt;%macro&lt;/SPAN&gt; m(var=%str(2,2,2,2))&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
	&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;/* don;t need this since you are defining var as macro parameter in macro stmt*/&lt;/SPAN&gt;

			&lt;SPAN class="token procnames"&gt;proc&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;surveyselect&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;subjects groups&lt;SPAN class="token operator"&gt;=(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;var)&lt;/SPAN&gt; reps&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; noprint
			    out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;randomizer&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;rename&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;groupId&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;reader&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
			&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token macrobound"&gt;%mend&lt;/SPAN&gt; m&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token macroname"&gt;%m&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429233#M106005</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T19:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429235#M106006</link>
      <description>&lt;P&gt;Thanks for the reply. My goal is to make it generalizable hence my desire to use it directly into the function. Would you know if that would be possible?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429235#M106006</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-19T19:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429240#M106008</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/72757"&gt;@Learning_S&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;Thanks for the reply. My goal is to make it generalizable hence my desire to use it directly into the function. Would you know if that would be possible?&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I am not quite sure what you mean by&amp;nbsp;&lt;SPAN&gt;generalizable&amp;nbsp; in your example. My thought was basically to avoid using so called manual unquote and let the macro processor unquote automatically as the text is passed to the compiler for execution.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;why do you need to have quotations here&amp;nbsp;"2,2,2,2"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429240#M106008</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T19:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429247#M106009</link>
      <description>&lt;P&gt;My goal is to be able to call the macro and use it solely with %m([numbers and commas]); where %m(2,2,2,2); was an example of that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"2,2,2,2" doesn't necessarily need to have quotes. I included them to my understanding of the %unquote() function and to have it written into the groups() option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to have the ability to put in different combinations of numbers into the % m(); macro&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g. 2,1,2&amp;nbsp; or&amp;nbsp; 4,4,3,2,3,2&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429247#M106009</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-19T19:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429251#M106010</link>
      <description>&lt;P&gt;still the same thing:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m(var);
	%let var=&amp;amp;var;

			proc surveyselect data=subjects groups=(&amp;amp;var) reps=3 noprint
			    out=randomizer(rename=groupId=reader); 
			run;
%mend m;%m(%str(2,2,2,2))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429251#M106010</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T19:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429252#M106011</link>
      <description>&lt;P&gt;I apologize. I misunderstood and thought that it could not be used in the macro. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429252#M106011</guid>
      <dc:creator>Learning_S</dc:creator>
      <dc:date>2018-01-19T19:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429253#M106012</link>
      <description>&lt;P&gt;It's all good. No big words like apologies needed. Makes mistakes to learn and share here. I was dumb 3 years ago when i wrote my first real code lol&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 19:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429253#M106012</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T19:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unquoting a Macro variable in a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429261#M106016</link>
      <description>&lt;P&gt;The easiest way is to not include commas in your macro parameter values. That is easy to do as in most cases SAS usually uses spaces as delimiters instead of commas. That is true for the IN () operator and also for the GROUPS= option on PROC SURVEYSELECT.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc surveyselect data=sashelp.class(obs=4) groups=(2 2) reps=3 noprint
  out=randomizer(rename=groupId=reader)
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really did need to pass in commas than find another way to protect that does not require macro quoting.&amp;nbsp; For example you could have the macro user pass in the parenthesis.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m(var);
proc surveyselect data=subjects
    groups=&amp;amp;var reps=3 noprint
    out=randomizer(rename=groupId=reader)
;
run;
%mend m;
%m(var=(2,2,2,2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;In fact SAS doesn't mind if you end up with a second set of parenthesis.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m(var);
proc surveyselect data=subjects
    groups=(&amp;amp;var) reps=3 noprint
    out=randomizer(rename=groupId=reader)
;
run;
%mend m;
%m((2,2,2,2))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your current macro would work fine without the %UNQUOTE() if you just called it without macro quoting the parameter values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%m(2 2 2 2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jan 2018 20:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unquoting-a-Macro-variable-in-a-Macro/m-p/429261#M106016</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-19T20:21:51Z</dc:date>
    </item>
  </channel>
</rss>

