<?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 USE in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694645#M211853</link>
    <description>&lt;P&gt;You have done the first step of macro writing, which is to create code that works for one situation without macros. Congratulations, most people don't do this step!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you insert macro language into this working code, which loops over all 3 data sets. In this case, the only thing that changes is the number after FRUIT_, so this is the only place that the loop will make changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
  %do i=1 %to 3;
    data fruit_&amp;amp;i;
      set fruit_&amp;amp;i;

      if total ge 5 then OVER = 1;
      else OVER = 0;
    run;
  %end;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Oct 2020 18:08:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-27T18:08:45Z</dc:date>
    <item>
      <title>MACRO USE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694636#M211851</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working to improve my knowledge of macro usage. My question is, is it possible to perform the same data step on three different datasets at one time using a macro as opposed to writing out the data step three different times. I know I can combine the datasets and perform the data step only once but I would like to explore macro options. My sample data is as follows:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fruit_1;&lt;BR /&gt;length FRUIT $10.; &lt;BR /&gt;input FRUIT $ TOTAL;&lt;BR /&gt;datalines; &lt;BR /&gt;Orange 2&lt;BR /&gt;Grape 31&lt;BR /&gt;Strawberry 5&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fruit_2;&lt;BR /&gt;length FRUIT $10.; &lt;BR /&gt;input FRUIT $ TOTAL;&lt;BR /&gt;datalines; &lt;BR /&gt;Cherry 20 &lt;BR /&gt;Lemon 15&lt;BR /&gt;Pineapple 4&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fruit_3;&lt;BR /&gt;length FRUIT $10.; &lt;BR /&gt;input FRUIT $ TOTAL;&lt;BR /&gt;datalines; &lt;BR /&gt;Apricot 12&lt;BR /&gt;Plum 5&lt;BR /&gt;Kiwi 16&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to run a datastep like below on all of the above datasets without having to rewrite the datastep two additional times.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data fruit_1; &lt;BR /&gt;set fruit_1; &lt;BR /&gt;&lt;BR /&gt;if total ge 5 then OVER = 1; &lt;BR /&gt;else OVER = 0; &lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 17:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694636#M211851</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-10-27T17:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO USE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694645#M211853</link>
      <description>&lt;P&gt;You have done the first step of macro writing, which is to create code that works for one situation without macros. Congratulations, most people don't do this step!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you insert macro language into this working code, which loops over all 3 data sets. In this case, the only thing that changes is the number after FRUIT_, so this is the only place that the loop will make changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
  %do i=1 %to 3;
    data fruit_&amp;amp;i;
      set fruit_&amp;amp;i;

      if total ge 5 then OVER = 1;
      else OVER = 0;
    run;
  %end;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 18:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694645#M211853</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-27T18:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO USE</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694646#M211854</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2020 18:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-USE/m-p/694646#M211854</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-10-27T18:15:01Z</dc:date>
    </item>
  </channel>
</rss>

