<?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: scanning all values in a macro array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818688#M323153</link>
    <description>&lt;P&gt;It's near impossible to figure out what you are trying to do from what you've posted. For starters there is no such thing as a macro array. Macro is just a text processor. I suggest you post a non-macro example of what you are trying to do - is it a series of SUM statements in an SQL query?&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jun 2022 20:10:18 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2022-06-16T20:10:18Z</dc:date>
    <item>
      <title>scanning all values in a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818684#M323150</link>
      <description>&lt;P&gt;This is a simplified version of what I'm trying to do.&amp;nbsp; &amp;nbsp;I use a dash because the actual number of variables quite large and am trying to avoid listing each one of them.&amp;nbsp; &amp;nbsp;Is there a way to get the macro to call up each variable in the array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options mprint;&lt;BR /&gt;data sample;&lt;BR /&gt;x1=1;&lt;BR /&gt;x2=3;&lt;BR /&gt;x3=2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro test(vars);&lt;BR /&gt;%let selcnt=%sysfunc(countw(&amp;amp;vars));&lt;BR /&gt;%do i=1 %to &amp;amp;selcnt;&lt;BR /&gt;%let selvar=%scan(&amp;amp;vars,&amp;amp;i);&lt;BR /&gt;sum(&amp;amp;selvar) as &amp;amp;selvar&lt;BR /&gt;%if &amp;amp;i lt &amp;amp;selcnt %then %do; , %end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select&lt;BR /&gt;%test(x1-x3)&lt;BR /&gt;from sample;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 19:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818684#M323150</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2022-06-16T19:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: scanning all values in a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818687#M323152</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Is there a way to get the macro to call up each variable in the array?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have not defined an array. However, if your goal is to find all variables in data set SAMPLE and then sum them, you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set sample;
    sum_all_variables=sum(of _numeric_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that's not your goal, then state your goal in words, instead of having us trying to decipher your macro code, which might not really be doing what you want anyway.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 20:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818687#M323152</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-16T20:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: scanning all values in a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818688#M323153</link>
      <description>&lt;P&gt;It's near impossible to figure out what you are trying to do from what you've posted. For starters there is no such thing as a macro array. Macro is just a text processor. I suggest you post a non-macro example of what you are trying to do - is it a series of SUM statements in an SQL query?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 20:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818688#M323153</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-06-16T20:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: scanning all values in a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818694#M323155</link>
      <description>&lt;P&gt;a simplified non-macro example would look something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;select sum(x1) as x1, sum(x2) as x2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;from sample;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; select sum(y1) as y1, sum(y2) as y2,....sum(yn) as yn&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from sample;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc, etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 20:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818694#M323155</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2022-06-16T20:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: scanning all values in a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818696#M323156</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have;
    var _numeric_;
    output out=want sum=;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9248"&gt;@Batman&lt;/a&gt; , as requested above, help us out and explain in words (not code) what you want.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 20:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818696#M323156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-16T20:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: scanning all values in a macro array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818699#M323159</link>
      <description>&lt;P&gt;The first line inside your macro with the way you called in the example is just plain wrong:&lt;/P&gt;
&lt;PRE&gt;%macro dummy(vars);
%let selcnt=%sysfunc(countw(&amp;amp;vars));
%put The number of words in &amp;amp;vars. is: &amp;amp;selcnt.;
%mend;

%dummy (x1-x3)&lt;/PRE&gt;
&lt;P&gt;Which will show this output:&lt;/P&gt;
&lt;PRE&gt;The number of words in x1-x3 is: 2
&lt;/PRE&gt;
&lt;P&gt;You only passed two words. To get what I think you expect you have to pass the list explicitly:&lt;/P&gt;
&lt;PRE&gt;395  %dummy (x1 x2 x3)
The number of words in x1 x2 x3 is: 3
&lt;/PRE&gt;
&lt;P&gt;Neither the macro language or SQL support "array" or "list" type syntax natively.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a large number of variables where you think an array or list shortcut is useful then look to procedures that support those ideas such as Proc Means/Summary.&lt;/P&gt;
&lt;P&gt;You might even try one of the reporting procedures:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.class;
   var _numeric_;
   table _numeric_, sum min max std
   ;
run;&lt;/PRE&gt;
&lt;P&gt;or &lt;/P&gt;
&lt;PRE&gt;proc report data=sashelp.class;
   columns _numeric_;
run;&lt;/PRE&gt;
&lt;P&gt;These procedures will use any valid list: like x1 - x3 (for sequentially named variables) x1 -- abc (for adjacent variables in column order), mixtures of the two as well as individual variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jun 2022 20:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-all-values-in-a-macro-array/m-p/818699#M323159</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-16T20:42:18Z</dc:date>
    </item>
  </channel>
</rss>

