<?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 filter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488520#M127338</link>
    <description>&lt;P&gt;Thanks Paige!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alana.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2018 12:34:18 GMT</pubDate>
    <dc:creator>Alana13</dc:creator>
    <dc:date>2018-08-21T12:34:18Z</dc:date>
    <item>
      <title>Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488359#M127277</link>
      <description>&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I made this macro, that filter my&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;data set&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(named A) by id and put it in a new&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;data set&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(named B), then I run the proc means procedure in my filtered data set. It works fine (code below).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input x y z id;
datalines;
1 2 3 1
4 5 6 1
7 8 9 2
4 8 7 2
1 4 7 2
4 8 9 3
;
run;

%macro filter(id);

 data B_&amp;amp;id;
 set A;
 where id = &amp;amp;id;
 run;

 proc means data=B_&amp;amp;id noprint;
 var x y z;
 output out=new_&amp;amp;id(keep=_STAT_ x y z);
 run;

 %mend filter;

 %filter(2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;But I need something more, I need that it runs over a specific list of ids and run proc means iteratively.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Like, if I code %filter(1 8 9) it should give as a result these three filtered data sets (B_1 B_8 and B_9) and the three data sets with proc means&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;result&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;(new_1 new_8 and new_9).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It will be used for several others procs too, some of then not allow the by option, so it's not a possibility.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;From&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;previous&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;search, I know that I should use the %do macro statement with %sysfunc, but I'm not sure how.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Can anyone share some ideas?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks, Alana.&lt;/DIV&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488359#M127277</guid>
      <dc:creator>Alana13</dc:creator>
      <dc:date>2018-08-20T20:48:30Z</dc:date>
    </item>
    <item>
      <title>Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488356#M127288</link>
      <description>&lt;DIV&gt;Hi,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I made this macro, that filter my data set (named A) by id and put it in a new data set (named B), then I run the proc means procedure in my filtered data set. It works fine (code below).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input x y z id;
datalines;
1 2 3 1
4 5 6 1
7 8 9 2
4 8 7 2
1 4 7 2
4 8 9 3
;
run;

%macro filter(id);

 data B_&amp;amp;id;
 set A;
 where id = &amp;amp;id;
 run;

 proc means data=B_&amp;amp;id noprint;
 var x y z;
 output out=new_&amp;amp;id(keep=_STAT_ x y z);
 run;

 %mend filter;

 %filter(2);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;But I need something more, I need that it runs over a specific list of ids and run proc means iteratively.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Like, if I code %filter(1 8 9) it should give as a result these three filtered data sets (B_1 B_8 and B_9) and the three data sets with proc means resut (new_1 new_8 and new_9).&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It will be used for several others procs too, some of then not allow the by option, so it's not a possibility.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;From previous search, I know that I should use the %do macro statement with %sysfunc, but I'm not sure how.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Can anyone share some ideas?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks, Alana.&lt;/DIV&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:44:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488356#M127288</guid>
      <dc:creator>Alana13</dc:creator>
      <dc:date>2018-08-20T20:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488360#M127278</link>
      <description>&lt;P&gt;Use a BY statement in PROC MEANS. Do not use macros for this purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=a;
    by id;
run;

proc means data=a noprint;
    by id;
    var x y z;
    output out=new;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want IDs 1 8 and 9 in the analysis, then change the above to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=a(where=(id in (1,8,9))) noprint;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488360#M127278</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-20T20:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488361#M127279</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the answer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, I&lt;SPAN&gt;&amp;nbsp;will use it for several others procs too, some of then do not allow the by statement, so it's not a possibility.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Alana.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488361#M127279</guid>
      <dc:creator>Alana13</dc:creator>
      <dc:date>2018-08-20T20:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488362#M127280</link>
      <description>&lt;P&gt;Almost every SAS PROC that does data analysis has a BY statement (and DATA steps have BY statements too).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So which data analysis PROC are you looking at that does not allow a BY statement?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488362#M127280</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-20T20:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488363#M127281</link>
      <description>&lt;P&gt;PROC optmodel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alana.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 20:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488363#M127281</guid>
      <dc:creator>Alana13</dc:creator>
      <dc:date>2018-08-20T20:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488364#M127282</link>
      <description>&lt;P&gt;Ok, you make a good point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run the analyses prior to OPTMODEL with a BY statement. Then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro do_this(ids);
    %let num_ids=%sysfunc(countw(&amp;amp;ids));
    %do i=1 %to &amp;amp;num_ids;
         %let this_id=%scan(&amp;amp;ids,&amp;amp;i,%str( ));
         proc optmodel;
             read data whatever(where=(id=&amp;amp;this_id)) ...
                  /* Proc OPTMODEL Statements go here */
             create data id_&amp;amp;this_id from ... ;
         run;
    %end;
%mend;

%do_this(1 8 9)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Aug 2018 21:16:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488364#M127282</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-20T21:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro filter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488520#M127338</link>
      <description>&lt;P&gt;Thanks Paige!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alana.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 12:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-filter/m-p/488520#M127338</guid>
      <dc:creator>Alana13</dc:creator>
      <dc:date>2018-08-21T12:34:18Z</dc:date>
    </item>
  </channel>
</rss>

