<?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 Error in SAS Studio in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240614#M74</link>
    <description>Please explain what you mean by it doesn't run in SAS Studio.</description>
    <pubDate>Wed, 23 Dec 2015 05:29:16 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-23T05:29:16Z</dc:date>
    <item>
      <title>MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240433#M66</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to automate repititive&amp;nbsp;filters&amp;nbsp;using a MACRO but is unsuccessful. Appreciate if you could review my script below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Blade&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;=======================&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;55&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;56 &lt;STRONG&gt;%macro a(STOCK);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;57 &lt;STRONG&gt;%a(PSE);&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;58&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;59 &lt;STRONG&gt;data _&amp;amp;stock; set PSE; where _NAME_="&amp;amp;stock"; run;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;60&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;61 &lt;STRONG&gt;%mend a;&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;62&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;63 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75&lt;/DIV&gt;</description>
      <pubDate>Tue, 22 Dec 2015 12:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240433#M66</guid>
      <dc:creator>Blade</dc:creator>
      <dc:date>2015-12-22T12:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240440#M67</link>
      <description>&lt;P&gt;What are you trying to do exactly? What is the benefit of the recursive macro call here exactly?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2015 14:25:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240440#M67</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2015-12-22T14:25:53Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240448#M68</link>
      <description>&lt;P&gt;Post example test data - in the form of a datastep, and what you want as output. &amp;nbsp;That code doesn't make any sense.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2015 14:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240448#M68</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-22T14:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240456#M69</link>
      <description>&lt;P&gt;You have your macro invocation inside your macro, that doesn't make sense. Macros are precompiled code, similar to a function in many other languages, but not a function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Declare Macro;
%macro a(STOCK);


 data _&amp;amp;stock; 
set PSE; 
where _NAME_="&amp;amp;stock"; 
run;

%mend a;

*make macro run;
%a(PSE);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Dec 2015 15:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240456#M69</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-22T15:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240607#M73</link>
      <description>&lt;P&gt;Thanks for the responses. To clarify, I have a mother dataset named &lt;STRONG&gt;PSE &lt;/STRONG&gt;and would like to extract/filter records from it using a field labelled as &lt;STRONG&gt;_NAME_&lt;/STRONG&gt;. The macro script is also expected to produce output files (_&lt;STRONG&gt;XXXX)&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've updated the script below to put comments. It seem to run successfully in SAS Base/EG, but not here in Studio. Thanks again for your time and patience.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;======================================&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro a(STOCK);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data _&amp;amp;stock;&lt;FONT color="#339966"&gt; /*NEW DATASET CREATED*/&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;set PSE; &amp;nbsp;&lt;FONT color="#339966"&gt;/*MOTHER DATASET*/&lt;/FONT&gt;&lt;BR /&gt;&amp;nbsp; where _NAME_="&amp;amp;stock";&lt;FONT color="#339966"&gt; /*FILTER APPLIED*/&lt;/FONT&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend a;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%a(PSE);&lt;BR /&gt;%a(2GO);&lt;BR /&gt;%a(EEI);&lt;/P&gt;</description>
      <pubDate>Wed, 23 Dec 2015 04:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240607#M73</guid>
      <dc:creator>Blade</dc:creator>
      <dc:date>2015-12-23T04:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240614#M74</link>
      <description>Please explain what you mean by it doesn't run in SAS Studio.</description>
      <pubDate>Wed, 23 Dec 2015 05:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240614#M74</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-23T05:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240625#M75</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually it is possible to call a macro within itself. &amp;nbsp;They are not generally compiled - unless you specifically compile to a library - and can be thought of like text replacements, they are recursive and should be used with caution as they can create infinitie loops. &amp;nbsp;In the usual fibonacci example these are used, this isn't fibonacci just shows it can be done:&lt;/P&gt;
&lt;PRE&gt;%macro Tmp (a);
  %if &amp;amp;a&amp;gt;0 %then %tmp (%eval(&amp;amp;a.-1));
  %put &amp;amp;a.;
%mend Tmp;

%tmp (1);
&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Dec 2015 09:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240625#M75</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-23T09:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO Error in SAS Studio</title>
      <link>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240626#M76</link>
      <description>&lt;P&gt;Post your log. &amp;nbsp;What doesn't work? &amp;nbsp;Remember the two software are different, do you have the relvan datasets available in each software? &amp;nbsp;Also note, that your code would look better if you did:&lt;/P&gt;
&lt;PRE&gt;data pse 2go eei fallout;
  set pse;
  select (_name_);
    when ("PSE") output pse;
    when ("2GO") output 2go;
    when ("EEI") output eei;
    otherwise output fallout;
  end;
run;

  &lt;/PRE&gt;
&lt;P&gt;I would avoid using _NAME_ as a variable, this is a SAS automated variable. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course you can automate it if there is a changing amount of datasets:&lt;/P&gt;
&lt;PRE&gt;data have;
  _name_="EEI"; output;
  _name_="2GO"; output;
  _name_="ABC"; output;
run;

proc sql noprint; 
  select  distinct "_"||strip(_NAME_)
  into    :DLIST separated by " "
  from    HAVE;
  create table LOOP as
  select  distinct cat("when ('",strip(_NAME_),"') output _",strip(_NAME_),";") as CMD
  from    HAVE;
quit;

data _null_;
  set loop end=last;
  if _n_=1 then call execute("data &amp;amp;DLIST. fallout; set have; select(_name_); ");
  call execute(cmd);
  if last then call execute(' otherwise output fallout; end; run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Dec 2015 10:09:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/MACRO-Error-in-SAS-Studio/m-p/240626#M76</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-12-23T10:09:33Z</dc:date>
    </item>
  </channel>
</rss>

