<?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 variable list separted by a comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110074#M22831</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestions, but I'm still having difficulty.&lt;/P&gt;&lt;P&gt;not sure where I'm going wrong, tried both possiblities:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %macro wordcount(macrolist);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %let i=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do %while (%scan(&amp;amp;macrolist, &amp;amp;i, ",") ^=%str());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let var=%scan(&amp;amp;macrolist, &amp;amp;i, " ");&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;%mend wordcount;&lt;/P&gt;&lt;P&gt;%put %wordcount(&amp;amp;i);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it end it up counting only 2 records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I tried this&lt;/P&gt;&lt;P&gt;%macro wordcount(macrolist);&lt;BR /&gt;/* Count the number of words in;*/&lt;BR /&gt;%local count;&lt;BR /&gt;%let count=0; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; %do %while(%qscan(%superq(&amp;amp;macrolist),&amp;amp;count+1,%str(, )) ne %str(, ));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let count = %eval(&amp;amp;count+1); &lt;BR /&gt;&amp;nbsp; %end;&lt;BR /&gt;&amp;amp;count &lt;BR /&gt;%mend wordcount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro assign;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to %wordcount(%superq(&amp;amp;macrolist));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let cvar&amp;amp;i=%scan(%superq(&amp;amp;macrolist),&amp;amp;i,%str(, ));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend assign;&lt;/P&gt;&lt;P&gt;%assign;&lt;BR /&gt; &lt;BR /&gt;%put &amp;amp;cvar1;&lt;BR /&gt;%put &amp;amp;cvar2;&lt;BR /&gt;%put &amp;amp;cvar3;&lt;BR /&gt;%put &amp;amp;cvar4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Got error&amp;nbsp; "invalid symbolic variable name".&lt;/P&gt;&lt;P&gt;Any suggestions ?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Feb 2013 22:58:53 GMT</pubDate>
    <dc:creator>suncawy</dc:creator>
    <dc:date>2013-02-14T22:58:53Z</dc:date>
    <item>
      <title>Macro variable list separted by a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110071#M22828</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Trying to accomplish a couple of things with a list of items. &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; This is my variable (separated by commas) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let macrolist = '79.01', '79.02',&amp;nbsp; '79.03',&amp;nbsp; '79.04';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; The first thing I'm trying to do is count the number of items in the list.&amp;nbsp;&amp;nbsp; So, I did find&lt;/P&gt;&lt;P&gt;&amp;nbsp; this code that does help in counting the items, but since I have commas in the list, I get an error (more parameters found&lt;/P&gt;&lt;P&gt;&amp;nbsp; than defined.&amp;nbsp; So, the first question is how do I count each item individually even though the comma is in there ?:&lt;/P&gt;&lt;P&gt; %macro wordcount (macrolist);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * Count the number of items in the list;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %local count;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let count = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do %while(%qscan( &amp;amp;macrolist, &amp;amp;count+1,&amp;nbsp;&amp;nbsp; %str( )) ne %str( ));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let count = %eval(&amp;amp;count + 1);&lt;/P&gt;&lt;P&gt;%end&lt;/P&gt;&lt;P&gt;&amp;amp;count&lt;/P&gt;&lt;P&gt;%mend wordcount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Then, I have this code to create macro variables for each item in the list.&amp;nbsp; Will this work even those commas separate the items ?:&lt;/P&gt;&lt;P&gt;%macro assign;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i = 1 %to %wordcount(&amp;amp;macrolist);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let cvar&amp;amp;i = %scan(&amp;amp;macrolist, &amp;amp;i,&amp;nbsp; %str( ));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend assign;&lt;/P&gt;&lt;P&gt;so the final outcome should be this:&lt;/P&gt;&lt;P&gt;cvar1 = '79.01'&lt;/P&gt;&lt;P&gt;cvar2 = '79.02'&lt;/P&gt;&lt;P&gt;cvar3 = '79.03'&lt;/P&gt;&lt;P&gt;cvar4 = '79.04'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance for the help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 19:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110071#M22828</guid>
      <dc:creator>suncawy</dc:creator>
      <dc:date>2013-02-14T19:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable list separted by a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110072#M22829</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why bother counting? Or creating the macro variables at all? I'm guessing your looking for a way to loop through a list and do something for each of the variables?&lt;/P&gt;&lt;P&gt;Hopefully the following helps:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*For looping through a list&lt;/P&gt;&lt;P&gt;%let i=1;&lt;/P&gt;&lt;P&gt;%do %while (%scan(&amp;amp;varlist, &amp;amp;i, ",") ^=%str());&lt;/P&gt;&lt;P&gt;%let var=%scan(&amp;amp;varlist, &amp;amp;i, " ");&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Increment counter;&lt;/P&gt;&lt;P&gt;%let i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 20:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110072#M22829</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-02-14T20:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable list separted by a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110073#M22830</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This may not be a complete list, but it will move you in the right direction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within the definition of %WORDCOUNT, replace &amp;amp;macrolist with %superq(macrolist).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within the definition of %ASSIGN, make the same change in two places.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Within the %LET statement, change the delimiter for %SCAN from %str( ) to %str(, ) so that both commas and blanks will be delimiters.&amp;nbsp; Note that this might not be the right thing to do for any and all applications, but it's necessary here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That might take care of it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 20:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110073#M22830</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-02-14T20:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable list separted by a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110074#M22831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestions, but I'm still having difficulty.&lt;/P&gt;&lt;P&gt;not sure where I'm going wrong, tried both possiblities:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; %macro wordcount(macrolist);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %let i=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do %while (%scan(&amp;amp;macrolist, &amp;amp;i, ",") ^=%str());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let var=%scan(&amp;amp;macrolist, &amp;amp;i, " ");&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let i=%eval(&amp;amp;i+1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;BR /&gt;%mend wordcount;&lt;/P&gt;&lt;P&gt;%put %wordcount(&amp;amp;i);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it end it up counting only 2 records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I tried this&lt;/P&gt;&lt;P&gt;%macro wordcount(macrolist);&lt;BR /&gt;/* Count the number of words in;*/&lt;BR /&gt;%local count;&lt;BR /&gt;%let count=0; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; %do %while(%qscan(%superq(&amp;amp;macrolist),&amp;amp;count+1,%str(, )) ne %str(, ));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let count = %eval(&amp;amp;count+1); &lt;BR /&gt;&amp;nbsp; %end;&lt;BR /&gt;&amp;amp;count &lt;BR /&gt;%mend wordcount;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro assign;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do i=1 %to %wordcount(%superq(&amp;amp;macrolist));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let cvar&amp;amp;i=%scan(%superq(&amp;amp;macrolist),&amp;amp;i,%str(, ));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend assign;&lt;/P&gt;&lt;P&gt;%assign;&lt;BR /&gt; &lt;BR /&gt;%put &amp;amp;cvar1;&lt;BR /&gt;%put &amp;amp;cvar2;&lt;BR /&gt;%put &amp;amp;cvar3;&lt;BR /&gt;%put &amp;amp;cvar4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Got error&amp;nbsp; "invalid symbolic variable name".&lt;/P&gt;&lt;P&gt;Any suggestions ?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2013 22:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110074#M22831</guid>
      <dc:creator>suncawy</dc:creator>
      <dc:date>2013-02-14T22:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable list separted by a comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110075#M22832</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure.&amp;nbsp; First, note that %superq assumes that you will pass the name of a macro variable.&amp;nbsp; So the proper syntax for your application would omit the ampersand:&amp;nbsp; %superq(macrolist)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Technically %superq(&amp;amp;macrolist) says that &amp;amp;macrolist resolves into the name of the macro variable that you would like to quote ... but I've never seen an application where that is needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It seems like you are switching logic when counting, to use both blanks and commas as delimiters.&amp;nbsp; But the loop should still end when %qscan returns a null string.&amp;nbsp; So the loop would look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%do %while (%qscan(%superq(macrolist), &amp;amp;count+1, %str(, )) ne );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The definition of %ASSIGN looks correct, once the ampersand is removed from &amp;amp;macrolist.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;See how that turns out ... might be done at that point.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Feb 2013 02:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-list-separted-by-a-comma/m-p/110075#M22832</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-02-15T02:46:49Z</dc:date>
    </item>
  </channel>
</rss>

