<?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: How can I run a macro over a list of inputs? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722900#M224232</link>
    <description>My list was space delimited, so this was exactly what I needed. Thank you!</description>
    <pubDate>Tue, 02 Mar 2021 16:34:42 GMT</pubDate>
    <dc:creator>tmcwill</dc:creator>
    <dc:date>2021-03-02T16:34:42Z</dc:date>
    <item>
      <title>How can I run a macro over a list of inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722891#M224228</link>
      <description>&lt;P&gt;I created a SAS macro, lets call it &lt;EM&gt;mymacro&lt;/EM&gt;, that takes a single string as input. I have a list of about 30 strings (with no pattern) that I need to run the macro for. I thought I could somehow put the strings in an array and then create another macro that loops the original macro over each item in the array, but I can't find information on how to create an array outside of a data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;List of input to &lt;EM&gt;mymacro&lt;/EM&gt;&amp;nbsp; : foo, world, dog, cat, tree, ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need a more efficient way of doing:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%mymacro&lt;/EM&gt;(foo)&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%mymacro&lt;/EM&gt;(world)&lt;/P&gt;&lt;P&gt;&lt;EM&gt;%mymacro&lt;/EM&gt;(dog)&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure there is a simple way of doing this, but I'm fairly new to macros in SAS. Thanks in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 16:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722891#M224228</guid>
      <dc:creator>tmcwill</dc:creator>
      <dc:date>2021-03-02T16:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a macro over a list of inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722898#M224231</link>
      <description>&lt;P&gt;If the "list" is space delimited I might suggest a macro "driver" to call your macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro driver (parmlist);
%do i=1 %to %sysfunc(countw(&amp;amp;parmlist.));
   %let word = %scan(&amp;amp;parmlist.,&amp;amp;i.);
   %mymacro (&amp;amp;word.);
%end;
%mend;

%driver (&amp;lt;your list goes here&amp;gt;)&lt;/PRE&gt;
&lt;P&gt;DO not use this with a comma delimited list as commas are default macro parameter separators and causes issues.&lt;/P&gt;
&lt;P&gt;If you have used a specific character to delimit your strings then it would go in the third position of %scan above. You may want to check the documentation for %scan to get the default list of delimiters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 16:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722898#M224231</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-02T16:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a macro over a list of inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722900#M224232</link>
      <description>My list was space delimited, so this was exactly what I needed. Thank you!</description>
      <pubDate>Tue, 02 Mar 2021 16:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722900#M224232</guid>
      <dc:creator>tmcwill</dc:creator>
      <dc:date>2021-03-02T16:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can I run a macro over a list of inputs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722902#M224234</link>
      <description>&lt;P&gt;If your list is in a SAS dataset then you could do this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic symbolgen ;
/* Create Sample Data */
data sample ;
	infile cards ;
	input string:$12. ;
cards;
This
is
my
test
data 
;

/* Sample Macro */
%macro myMacro(param1) ;
	put "param1 :" &amp;amp;param1 ;
%mend ;

data _null_ ;
	/* read Sample data and call macro passing a parameter */
	set sample ;
	%myMacro(string) ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Mar 2021 16:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-run-a-macro-over-a-list-of-inputs/m-p/722902#M224234</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-03-02T16:35:30Z</dc:date>
    </item>
  </channel>
</rss>

