<?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: Repeated Procedure / Loop in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25500#M5781</link>
    <description>Use the BY Group Processing mentioned by Patrick. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
As for what's wrong with the code....&lt;BR /&gt;
&lt;BR /&gt;
In your procedure your repeated using the dataset_a but then you're deleting all observations?  in the second loop the observations won't be there...&lt;BR /&gt;
&lt;BR /&gt;
You probably want to append the data at the end, not merge as well...&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Reeza</description>
    <pubDate>Fri, 21 May 2010 16:01:04 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2010-05-21T16:01:04Z</dc:date>
    <item>
      <title>Repeated Procedure / Loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25498#M5779</link>
      <description>I have the following dataset:&lt;BR /&gt;
datset_a                                &lt;BR /&gt;
obs          firm          &lt;BR /&gt;
1              A             &lt;BR /&gt;
2              B            &lt;BR /&gt;
3              C           &lt;BR /&gt;
...             ...&lt;BR /&gt;
For each observation I need to carry out several procedures which I programmed already. So for example, if I take observation 1, after running my program I will obtain a dataset looking like this:&lt;BR /&gt;
obs          firm        X          Y       ....&lt;BR /&gt;
1             A           aaa       aav&lt;BR /&gt;
&lt;BR /&gt;
What I need is a program that takes observation 1, runs the procedures, then goes on to observation 2, runs the procedures, etc. All outputs should then be combined again in a dataset looking like this: &lt;BR /&gt;
obs          firm        X          Y   ....&lt;BR /&gt;
1             A           aaa       aav&lt;BR /&gt;
2             B           dfsa      dfa&lt;BR /&gt;
3             C           adf       dga&lt;BR /&gt;
&lt;BR /&gt;
I tried using the following code:&lt;BR /&gt;
%macro match;&lt;BR /&gt;
%Do i=1 %to 400;&lt;BR /&gt;
&lt;BR /&gt;
data dataset_a;&lt;BR /&gt;
set dataset_a;&lt;BR /&gt;
if nobs ne &amp;amp;i then delete;&lt;BR /&gt;
&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
&lt;BR /&gt;
data dataset_a1;&lt;BR /&gt;
merge dataset_a1 b;&lt;BR /&gt;
by obs;&lt;BR /&gt;
run;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend match;&lt;BR /&gt;
%match;&lt;BR /&gt;
&lt;BR /&gt;
Any idea what is wrong or how I can solve my problem alternatively?&lt;BR /&gt;
Thanks.&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 May 2010 07:08:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25498#M5779</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-05-21T07:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Procedure / Loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25499#M5780</link>
      <description>Hi Tina&lt;BR /&gt;
&lt;BR /&gt;
Reading your post I'm having the following thoughts:&lt;BR /&gt;
&lt;BR /&gt;
I believe you shouldn't try to solve this problem with a macro but to use by group processing.&lt;BR /&gt;
&lt;BR /&gt;
Just prepare your data for the procedures, sort them by observation (must be a variable like ID) and then use things like: proc print; by id; run;&lt;BR /&gt;
&lt;BR /&gt;
You should only use a macro if you can't do it with normal SAS code. People tend too often too fast to use macros instead of re-designing their approach.&lt;BR /&gt;
&lt;BR /&gt;
If it really has to be a macro: Look up "call execute" and how it works.&lt;BR /&gt;
&lt;BR /&gt;
What you attempt to do is multiplying your SAS code 400 times (with minor alterations- but always accessing the same table 400 times). Even if you manage to get that working it will be bad design and perform badly.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 21 May 2010 11:14:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25499#M5780</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-05-21T11:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Repeated Procedure / Loop</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25500#M5781</link>
      <description>Use the BY Group Processing mentioned by Patrick. &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
As for what's wrong with the code....&lt;BR /&gt;
&lt;BR /&gt;
In your procedure your repeated using the dataset_a but then you're deleting all observations?  in the second loop the observations won't be there...&lt;BR /&gt;
&lt;BR /&gt;
You probably want to append the data at the end, not merge as well...&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Reeza</description>
      <pubDate>Fri, 21 May 2010 16:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Repeated-Procedure-Loop/m-p/25500#M5781</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-05-21T16:01:04Z</dc:date>
    </item>
  </channel>
</rss>

