<?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: Passing an array to a Macro in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237504#M55364</link>
    <description>Thank you so so much! It worked like a miracle.</description>
    <pubDate>Thu, 03 Dec 2015 00:06:38 GMT</pubDate>
    <dc:creator>braverju</dc:creator>
    <dc:date>2015-12-03T00:06:38Z</dc:date>
    <item>
      <title>Passing an array to a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237422#M55348</link>
      <description>&lt;P&gt;Hello! I am new to SAS macro and would appreciate your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code that I would like to put into Macro to be able to run with different parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA myData;&lt;BR /&gt;set myData;&lt;BR /&gt;&lt;BR /&gt;ratio1 = freq1/N1;&lt;BR /&gt;ratio2 = freq2/N2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Label&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ratio1 = '% Label 1'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ratio2 = '% Label 2'&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;***************************************&lt;/P&gt;&lt;P&gt;I would like to create a macro function that has the following parameters:&lt;/P&gt;&lt;P&gt;1) Data&amp;nbsp;set&lt;/P&gt;&lt;P&gt;2) Array of Labels (Label 1, Label 2...) with the dynamic length&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, I would like to be able to do something like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO calculateRatio&amp;nbsp;(dataSet, lbls);&lt;/P&gt;&lt;P&gt;DATA &amp;amp;&lt;SPAN&gt;dataSet&lt;/SPAN&gt;;&lt;BR /&gt;&amp;nbsp;set&amp;nbsp;&lt;SPAN&gt;&amp;amp;&lt;SPAN&gt;dataSet&lt;/SPAN&gt;&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;%do i=1 %to %dim(lbls);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ratio&amp;amp;i =f&lt;SPAN&gt;req&amp;amp;i/N&amp;amp;i&amp;nbsp;&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%end; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Label&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do i=1 %to&amp;nbsp;&lt;SPAN&gt;%dim(lbls)&lt;/SPAN&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ratio&amp;amp;i = %:_&amp;amp;&amp;amp;lbls&amp;amp;i;&lt;BR /&gt;%end;&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%MEND&amp;nbsp;&lt;SPAN&gt;c&lt;/SPAN&gt;&lt;SPAN&gt;alculateRatio;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;***********&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%ARRAY (lbls, VALUES=Label1 Label2);&lt;BR /&gt;%&lt;SPAN&gt;c&lt;/SPAN&gt;&lt;SPAN&gt;alculateRatio&amp;nbsp;&lt;/SPAN&gt;(myData, lbls);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Till now – no luck. I also tried %DO_OVER(lbls,PHRASE=ratio?_I_ = ?) but keep getting tons of syntax errors. The code doesn't work and I am afraid I am doing something basically wrong. The help is highly appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2015 18:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237422#M55348</guid>
      <dc:creator>braverju</dc:creator>
      <dc:date>2015-12-02T18:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an array to a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237435#M55352</link>
      <description>&lt;P&gt;You are confusing and combining ARRAY commands with MACRO commands, can't be done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to use MACRO commands when you are performing macro functions. The fact that loops can be EITHER arrays or macros doesn't mean you can use array command as macro commands. There is no %dim macro command, dim is an array command. The code below assumes in &amp;amp;lbls you have a delimiter of backslash to separate the labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO calculateRatio (dataSet, lbls);
DATA &amp;amp;dataSet;
 set &amp;amp;dataSet;
 %do i=1 %to %sysfunc(countw(%superq(lbls),\));
        ratio&amp;amp;i =freq&amp;amp;i/N&amp;amp;i ;
%end;

Label
        %do i=1 %to %sysfunc(countw(%superq(lbls),\));
        ratio&amp;amp;i = "%str(%%) %scan(&amp;amp;lbls,&amp;amp;i,\)"
%end;
;
RUN;

%MEND calculateRatio;

%calculateRatio(myData,Label 1\Label 2)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2015 19:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237435#M55352</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-12-02T19:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an array to a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237437#M55353</link>
      <description>&lt;P&gt;Pass the list of labels as a single parameter that is delimited by some character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro calculateRatio (inds,outds, labels);
%local i ;
data &amp;amp;outds;
  set &amp;amp;indst;
%do i=1 %to %sysfunc(countw(&amp;amp;labels,|));
    ratio&amp;amp;i =freq&amp;amp;i/N&amp;amp;i ; 
    label ratio&amp;amp;i = %sysfunc(quote(%qscan(&amp;amp;labels,&amp;amp;i,|)));
%end;
run;
%mend calculateRatio;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;%calculateratio(inds=have,outds=want,labels=Label1|Label2|Label3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2015 19:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237437#M55353</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-12-02T19:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an array to a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237504#M55364</link>
      <description>Thank you so so much! It worked like a miracle.</description>
      <pubDate>Thu, 03 Dec 2015 00:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237504#M55364</guid>
      <dc:creator>braverju</dc:creator>
      <dc:date>2015-12-03T00:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Passing an array to a Macro</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237505#M55365</link>
      <description>Thank you so much for the explanations! I got it. I was confused indeed. And it worked now. Thank you!</description>
      <pubDate>Thu, 03 Dec 2015 00:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Passing-an-array-to-a-Macro/m-p/237505#M55365</guid>
      <dc:creator>braverju</dc:creator>
      <dc:date>2015-12-03T00:07:40Z</dc:date>
    </item>
  </channel>
</rss>

