<?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 how to set up parameters in marco in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937253#M368263</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question on how to set up macro&amp;nbsp;parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I set up my marco as following (just an idea):&lt;/P&gt;
&lt;PRE&gt;%macro m_test(varlst=); /*if input varlst=var1 var2*/
...
y=('ID', &amp;amp;varlst.); /*I want 'var1', 'var2' here*/
by &amp;amp;varlst. /*var1 var2*/
...
%mend;

&lt;/PRE&gt;
&lt;P&gt;current code won't work as &amp;amp;varlst.=var1 var2 only. Is it a way to get " 'var1', 'var2'" part done without setting up additional&amp;nbsp;parameters? try to see whether I use minimal&amp;nbsp;parameters to setup most codes and stuck at this&amp;nbsp; situation.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2024 14:12:00 GMT</pubDate>
    <dc:creator>stataq</dc:creator>
    <dc:date>2024-07-26T14:12:00Z</dc:date>
    <item>
      <title>how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937253#M368263</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question on how to set up macro&amp;nbsp;parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I set up my marco as following (just an idea):&lt;/P&gt;
&lt;PRE&gt;%macro m_test(varlst=); /*if input varlst=var1 var2*/
...
y=('ID', &amp;amp;varlst.); /*I want 'var1', 'var2' here*/
by &amp;amp;varlst. /*var1 var2*/
...
%mend;

&lt;/PRE&gt;
&lt;P&gt;current code won't work as &amp;amp;varlst.=var1 var2 only. Is it a way to get " 'var1', 'var2'" part done without setting up additional&amp;nbsp;parameters? try to see whether I use minimal&amp;nbsp;parameters to setup most codes and stuck at this&amp;nbsp; situation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 14:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937253#M368263</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-26T14:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937255#M368265</link>
      <description>&lt;P&gt;Please explain what this line of code is trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y=('ID', &amp;amp;varlst.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that as shown, this line of code is not valid working legal SAS code, and will never work regardless of the value of &amp;amp;VARLST, it will never work either in a macro or outside of a macro. So you not only need to explain what this line of code is trying to do, but you need to do it in a way that is legal valid working SAS code.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 14:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937255#M368265</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-26T14:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937259#M368267</link>
      <description>&lt;P&gt;I'm not sure what the purpose of this macro is, but I'm not sure you can use positional parameters when you want a macro variable to be several different variables. Using keyword parameters might work (keyword parameters are not defined with an = sign in the %macro statement). Does this help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(varlist);
proc means data=sashelp.class maxdec=2;
var &amp;amp;varlist;
run;
%mend;
%test(age height weight)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2024 14:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937259#M368267</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2024-07-26T14:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937263#M368269</link>
      <description>Just want to know whether there is a way i can get " 'var1', 'var2' " within my marco setup if I call %m_test(varlst=var1 var2); additional work  will be needed.</description>
      <pubDate>Fri, 26 Jul 2024 14:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937263#M368269</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-26T14:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937266#M368270</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;
&lt;P&gt;current code won't work as &amp;amp;varlst.=var1 var2 only. Is it a way to get " 'var1', 'var2'" part done without setting up additional&amp;nbsp;parameters? try to see whether I use minimal&amp;nbsp;parameters to setup most codes and stuck at this&amp;nbsp; situation.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is your actual question "how do I place quotes around the elements of the variable varlist"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's one way placing the quoted values into a new variable to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro junk(varlist=);
%let newlist=;
%do i = 1 %to %sysfunc(countw(&amp;amp;varlist.));
   %let word=%scan(&amp;amp;varlist.,&amp;amp;i.);
   %let newlist = &amp;amp;newlist. %sysfunc(quote(&amp;amp;word.));
%end;
/* just to show the result*/
%put &amp;amp;newlist.;
%mend;

%junk(varlist= var1 var2);
&lt;/PRE&gt;
&lt;P&gt;But to reiterate, your example "code' with "y= ('ID',&amp;amp;newlist.) " using the new variable with quoted values is &lt;STRONG&gt;still invalid SAS code.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 15:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937266#M368270</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-26T15:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937271#M368271</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448857"&gt;@stataq&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Just want to know whether there is a way i can get " 'var1', 'var2' " within my marco setup if I call %m_test(varlst=var1 var2); additional work will be needed.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I asked what this line of code is trying to do. Please reply.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 15:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937271#M368271</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-26T15:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937273#M368273</link>
      <description>Your suggestion solved 50% question. Now we need to find a way to add "," in between. &lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt; A great mind twister.  Much appreciated your input and kindness.&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;</description>
      <pubDate>Fri, 26 Jul 2024 15:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937273#M368273</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-26T15:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937275#M368274</link>
      <description>&lt;P&gt;If you can use double quotes ""&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m_test(varlst=); /*if input varlst=var1 var2*/
%local new_varlst;

%let new_varlst = "%sysfunc(tranwrd(&amp;amp;varlst.,%str( ),%str(%", %")))";

%put &amp;amp;=varlst.;
%put &amp;amp;=new_varlst.;
%mend;

%m_test(varlst=a b c d e f g)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need single try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m_test2(varlst=); /*if input varlst=var1 var2*/
%local new_varlst;

%let new_varlst = %str(%')%qsysfunc(tranwrd(&amp;amp;varlst.,%str( ),%str(%', %')))%str(%');

%put &amp;amp;=varlst.;
%put &amp;amp;=new_varlst.;
%mend;

%m_test2(varlst=a b c d e f g)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you would tell us what do you want to do, maybe we could suggest something that is less "scratch left year with right... foot" approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 15:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937275#M368274</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-07-26T15:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937277#M368275</link>
      <description>&lt;P&gt;Your answer solved my question 100%. &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":rose:"&gt;🌹&lt;/span&gt;. My intend is to have a setup where I have "var1 var2" and "'var1','var2'" at the same time and only need to setup one macro parameter "varlst=var1 var2". It is a hypothetical situation. I am really appreciate &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; 's kindness and willingness to such question. &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 15:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937277#M368275</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-07-26T15:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937280#M368276</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/448857"&gt;@stataq&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Your suggestion solved 50% question. Now we need to find a way to add "," in between. &lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt; A great mind twister. Much appreciated your input and kindness.&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;extremely simple&lt;/P&gt;
&lt;PRE&gt;&lt;STRIKE&gt; %let newlist = %sysfunc(catx(',',&amp;amp;newlist.&lt;FONT color="#000000"&gt;,&lt;/FONT&gt; %sysfunc(quote(&amp;amp;word.))));&lt;/STRIKE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRIKE&gt;The catx function places the first parameter between the following values. If there is only one Var in the var list then no comma would be inserted because the first time the loop executes the &amp;amp;newlist is blank and so nothing to insert between.&lt;/STRIKE&gt; For some reason that calls %sysevalf. Gets the correct result though shows an error in the log.&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%do i = 1 %to %sysfunc(countw(&amp;amp;varlist.));
   %let word=%scan(&amp;amp;varlist.,&amp;amp;i.);
   %if &amp;amp;i=1 %then %let newlist=%sysfunc(quote(&amp;amp;word.));
   %else %let newlist = &amp;amp;newlist.,%sysfunc(quote(&amp;amp;word.));
%end;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2024 20:54:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937280#M368276</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-07-26T20:54:19Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up parameters in marco</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937427#M368346</link>
      <description>&lt;P&gt;If you told us upfront that you need it for a hash table it could be even easier, because it doesn't requires quotes and commas at all...&lt;/P&gt;
&lt;P&gt;See:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/a-question-on-how-to-call-a-macro-variable-within-a-macro/m-p/937425#M368344" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/a-question-on-how-to-call-a-macro-variable-within-a-macro/m-p/937425#M368344&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2024 11:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-parameters-in-marco/m-p/937427#M368346</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-07-29T11:17:28Z</dc:date>
    </item>
  </channel>
</rss>

