<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634852#M188447</link>
    <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; , almost! This stores 5 copies of the same dataset.&lt;BR /&gt;I was looking for one per animal.</description>
    <pubDate>Wed, 25 Mar 2020 17:55:33 GMT</pubDate>
    <dc:creator>RedBishop</dc:creator>
    <dc:date>2020-03-25T17:55:33Z</dc:date>
    <item>
      <title>Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634837#M188436</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a short question that hopefully someone knows the answer to.&lt;/P&gt;&lt;P&gt;Suppose you'd wish to simply extract 5 datasets from 1 dataset, using a macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyMacro;
%do i = 1 %to 5; 
     CurrentAnimal = ('dog', 'cat', 'sheep', 'cow', 'horse') (i)

     proc sql;
     create table Want_ &amp;amp; i as
     select *
     from Have&lt;BR /&gt;     where Animal = CurrentAnimal;
     quit;

%end;
%mend MyMacro;

%MyMacro&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It gives no errors, but no output either.&lt;/P&gt;&lt;P&gt;Anyone knows what's going on and how to fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634837#M188436</guid>
      <dc:creator>RedBishop</dc:creator>
      <dc:date>2020-03-25T17:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634841#M188440</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/317271"&gt;@RedBishop&lt;/a&gt;&amp;nbsp; Are you after this by any chance?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro MyMacro;&lt;BR /&gt; %let   CurrentAnimal = 'dog', 'cat', 'sheep', 'cow', 'horse';
%do i = 1 %to 5; 
   

     proc sql;
     create table Want_&amp;amp;i as
     select *
     from Have     
         where Animal in (&amp;amp;CurrentAnimal);
     quit;

%end;
%mend MyMacro;
%mymacro  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634841#M188440</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-25T17:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634847#M188443</link>
      <description>&lt;P&gt;Usually not a good idea to chop up a large data set into five (or any other number) of subsets. Whatever analysis you were going to do can be done with the one big data set and a BY statement, which simplifies your programming considerably, compared to programming an analysis to do the same thing over five data sets.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634847#M188443</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-25T17:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634849#M188444</link>
      <description>&lt;P&gt;Since I don't have your data I used sashelp.cars.&amp;nbsp; How about this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro MyMacro;
%let CurrentAnimal =Audi, BMW; 
%let dim=%sysfunc(countw(%quote(&amp;amp;CurrentAnimal.),%str(,)));
%do i = 1 %to &amp;amp;dim;
  %let this=%scan(%quote(&amp;amp;CurrentAnimal.),&amp;amp;i,%str(,));
     proc sql;
     create table Want_&amp;amp;this. as
     select *
     from sashelp.cars where make = "&amp;amp;this.";
     quit;
%end;
%mend MyMacro;
%MyMacro&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634849#M188444</guid>
      <dc:creator>JerryV</dc:creator>
      <dc:date>2020-03-25T17:53:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634852#M188447</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; , almost! This stores 5 copies of the same dataset.&lt;BR /&gt;I was looking for one per animal.</description>
      <pubDate>Wed, 25 Mar 2020 17:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634852#M188447</guid>
      <dc:creator>RedBishop</dc:creator>
      <dc:date>2020-03-25T17:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634853#M188448</link>
      <description>&lt;P&gt;Or maybe&lt;/P&gt;
&lt;PRE&gt;%macro MyMacro;
%let CurrentAnimal = dog cat sheep cow horse;
%do i = 1 %to %sysfunc(countw,&amp;amp;CurrentAnimal.); 
	  %let animal = %scan(&amp;amp;CurrentAnimal.,&amp;amp;i.);
     proc sql;
     create table Want_&amp;amp;i as
     select *
     from Have     where Animal = "&amp;amp;Animal.";
     quit;

%end;
%mend MyMacro;

%MyMacro&lt;/PRE&gt;
&lt;P&gt;Your posted code has a large number of errors. First your currentanimal assignment statement is 1) not terminated and 2) out side of a data step and 3) has a very mysterious (i) at the end that would not be acceptable in any syntax for SAS. I have assumed that you want the macro to process the values and placed the value into a Macro variable using the %let statment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second in your Proc Sql you have multiple spaces in what appears to be the name you want the table to have between the underscore and the data set number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am counting the number of words in the list of the animals and selecting each one as it appears with the %scan function to get one word at a time from the list.&lt;/P&gt;
&lt;P&gt;Then in the where clause I am assuming you want one data set when the value matches exactly the animal. The macro value is placed in double quotes so the animal will resolve and be seen by proc sql. If the case does not match the results won't either. If the list has "dog" and the source data set has "Dog" you do not get a match. You may need to use one of the case functions to get comparable values for the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634853#M188448</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-25T17:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634854#M188449</link>
      <description>&lt;P&gt;Ah ok, it appears others have read the question correctly and have posted the needed solution&lt;/P&gt;</description>
      <pubDate>Wed, 25 Mar 2020 17:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634854#M188449</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-25T17:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634857#M188450</link>
      <description>Thanks a lot &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; and others!</description>
      <pubDate>Wed, 25 Mar 2020 18:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/634857#M188450</guid>
      <dc:creator>RedBishop</dc:creator>
      <dc:date>2020-03-25T18:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/635008#M188513</link>
      <description>&lt;P&gt;Recommendation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Use WHERE to select data partitions and BY to process them group wise.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cutting a poor innocent data set into pieces could bring the wrath of PETADS (People for the Ethical Treatment of Data Sets) down on you!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 11:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/635008#M188513</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-03-26T11:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/635015#M188517</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Recommendation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Use WHERE to select data partitions and BY to process them group wise.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cutting a poor innocent data set into pieces could bring the wrath of PETADS (People for the Ethical Treatment of Data Sets) down on you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes. There's a reason why SAS doesn't provide a built-in way to split data sets like this; you have to write a macro which is not easy for many people. On the other hand, SAS did build in the BY statement and the WHERE statement to allow handling of different groups in one large data set.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 12:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/635015#M188517</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-03-26T12:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/635016#M188518</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;, I wish elders like you stipulated rules to adhere over the years unlike what I notice in industry. Sometimes, I feel academia leap frogs so much and on the other hand, industry seems to unwilling to adopt best practices. Kudos for surviving for decades &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 12:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro/m-p/635016#M188518</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-26T12:20:04Z</dc:date>
    </item>
  </channel>
</rss>

