<?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: Count number of arguments in a macro var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765710#M242547</link>
    <description>&lt;P&gt;You don't need to ask in this forum what an option does. The meaning of "g" is in the documentation for CALL SYMPUTX, please look it up.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here's a case where you can answer your question yourself. Try running the code WITHOUT the PUT function. What happens? Does that answer the question?&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 19:36:08 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-09-02T19:36:08Z</dc:date>
    <item>
      <title>Count number of arguments in a macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765709#M242546</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I saw this code that :&lt;/P&gt;
&lt;P&gt;a- Define a macro varaible called vector with concatenated values (with comma between the values)&lt;/P&gt;
&lt;P&gt;b- Define a macro varaible called n that count number of arguments in macro varaible vector (3 in this example)&lt;/P&gt;
&lt;P&gt;I want to ask please about the code:&lt;/P&gt;
&lt;P&gt;Why are there 3 arguments to CALL SYMPUTX? What is the meaning of 'g'? Why do we use PUT fucction with best. format?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector = type1,type2,type3;
data _null_;
call symputx('n',put(countw("&amp;amp;vector.",','),best.),'g');
run;
%put &amp;amp;n.;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Sep 2021 19:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765709#M242546</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-02T19:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of arguments in a macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765710#M242547</link>
      <description>&lt;P&gt;You don't need to ask in this forum what an option does. The meaning of "g" is in the documentation for CALL SYMPUTX, please look it up.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here's a case where you can answer your question yourself. Try running the code WITHOUT the PUT function. What happens? Does that answer the question?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 19:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765710#M242547</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-02T19:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of arguments in a macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765711#M242548</link>
      <description>&lt;P&gt;First and second questions, the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1fa0ay5pzr9yun1mvqxv8ipzd4d.htm" target="_self"&gt;documentation&lt;/A&gt; is pretty straightforward here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="xisDoc-keyword"&gt;CALL SYMPUTX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;macro-variable&lt;/EM&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#800080"&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;value&lt;/EM&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN class="xisDoc-optional"&gt;&amp;lt;,&amp;nbsp;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;&amp;gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;..&lt;/SPAN&gt;&lt;/P&gt;
&lt;H4 class="xisDoc-argument"&gt;&lt;STRONG&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;&lt;/STRONG&gt;&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;specifies a character constant, variable, or expression. The value of&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is not case sensitive. The first non-blank character in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;specifies the symbol table in which to store the macro variable. The following values are valid as the first non-blank character in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;:&lt;/P&gt;
&lt;DIV id="p16rxe2wnz9us9n17mdhd8mgih89" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;G&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;specifies that the macro variable is stored in the global symbol table, even if the local symbol table exists.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="p0u7a2o4yp95cnn1p57rqy17j2ir" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;L&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;specifies that the macro variable is stored in the most local symbol table that exists, which will be the global symbol table, if used outside a macro.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV id="n1ra7vcb4u7wipn19n0nmpqahoze" class="xisDoc-argDescriptionPair"&gt;
&lt;H4 class="xisDoc-argument"&gt;F&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;specifies that if the macro variable exists in any symbol table, CALL SYMPUTX uses the version in the most local symbol table in which it exists. If the macro variable does not exist, CALL SYMPUTX stores the variable in the most local symbol table.&lt;/P&gt;
&lt;DIV id="p0a8csw8mjawgbn1saw1z0fi7ibm" class="xisDoc-note"&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;&lt;SPAN class="xisDoc-noteGenText"&gt;Note:&amp;nbsp;&lt;/SPAN&gt;If you omit&amp;nbsp;&lt;EM class="xisDoc-userSuppliedValue"&gt;symbol-table&lt;/EM&gt;, leave it blank or use any other symbol other than G, L, or F. CALL SYMPUTX stores the macro variable in the same symbol table as does the CALL SYMPUT routine.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&lt;FONT color="#000000"&gt;To answer your third question - try it with and without the BEST function and see what happens...except the code you posted doesn't work at all so you may want to revisit that first.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I saw this code that :&lt;/P&gt;
&lt;P&gt;a- Define a macro varaible called vector with concatenated values (with comma between the values)&lt;/P&gt;
&lt;P&gt;b- Define a macro varaible called n that count number of arguments in macro varaible vector (3 in this example)&lt;/P&gt;
&lt;P&gt;I want to ask please about the code:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Why are there 3 arguments to CALL SYMPUTX? What is the meaning of 'g'? Why do we use PUT fucction with best. format?&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector = type1,type2,type3;
data _null_;
call symputx('n,put(countw("&amp;amp;vector.",','),best.),'g');
run;
%put &amp;amp;n.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;FONT color="#000000"&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="xisDoc-note"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 02 Sep 2021 19:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765711#M242548</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-02T19:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of arguments in a macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765794#M242589</link>
      <description>&lt;P&gt;The G value for the third option forces the generated macro variable into the GLOBAL macro scope, even if you are running the code inside a macro.&lt;/P&gt;
&lt;P&gt;The PUT() function call is not needed with CALL SYMPUTX(), especially if you are just going to use the BEST format, because CALL SYMPUTX() will automatically convert numbers in the second argument into strings to store in the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect the code used to use the older CALL SYMPUT() function that did not support the third parameter.&amp;nbsp; So when they switched to to using CALL SYMPUTX() so they could insure the macro variable value was written into the global scope then just left the PUT() function in the code.&amp;nbsp; (Or perhaps is was just an older CODER instead of older CODE).&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 03:41:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765794#M242589</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-03T03:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of arguments in a macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765795#M242590</link>
      <description>&lt;P&gt;Nowadays you can call COUNTW() in macro code if you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vector = type1,type2,type3;
%global n;
%let n=%sysfunc(countw(%quote(&amp;amp;vector),%str(,)));
%put &amp;amp;=n;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why the commas? Where is the value used in the code? Are those variable names that you need to include in SQL code?&amp;nbsp; Because if you want to use a list of variables in normal SAS code then use a space between the names. Plus using space instead of comma means it is easier to use the value with macro calls.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 03:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-arguments-in-a-macro-var/m-p/765795#M242590</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-03T03:48:39Z</dc:date>
    </item>
  </channel>
</rss>

