<?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 Automating execution of the same sas code n times in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59380#M12855</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset called DataSetA which has n observations. I have a smoothly running sas programme called ProgB. ProgB takes one observation at a time of DataSetA, beginning with the first one, does a whole bunch of stuff and updates DataSetB with a new record or changes an existing record. What I want to do is execute ProgB once for each observation of DataSetA. I am doing this manually at the moment by changing a macro variable, which is the observation number of DataSetA: manually updating the observation number: 1, 2, 3, ...,n and manually pressing the SAS programme execution button each time. I would like to automate this simple process, but I don't know how. Could you please help me?&lt;BR /&gt;
&lt;BR /&gt;
I use PC SAS. I looked at some available tutorials and tips on SAS macros and functions, but I am overwhelmed by all the information for what I think is a really simple automation task. I have read that macros and functions cannot accommodate data steps, even the rather simple ones that I have in my ProgB (but I could be wrong). Any tips on what I can do?&lt;BR /&gt;
&lt;BR /&gt;
Algorithmically, all I want do is:&lt;BR /&gt;
&lt;BR /&gt;
Do i = 1 to n;&lt;BR /&gt;
     GetNextDataSetAObsvn(i);       /* puts DataSetA observation i in a table with only one observation */ &lt;BR /&gt;
     ExecuteProgB;                            /* executes lots of data steps, procs, etc on this single obsvn and updates DataSetB with the result */&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
But I don't know how to do this in PC SAS, even after trying for many hours!&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Ian.</description>
    <pubDate>Thu, 28 Apr 2011 15:07:44 GMT</pubDate>
    <dc:creator>iank131</dc:creator>
    <dc:date>2011-04-28T15:07:44Z</dc:date>
    <item>
      <title>Automating execution of the same sas code n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59380#M12855</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a dataset called DataSetA which has n observations. I have a smoothly running sas programme called ProgB. ProgB takes one observation at a time of DataSetA, beginning with the first one, does a whole bunch of stuff and updates DataSetB with a new record or changes an existing record. What I want to do is execute ProgB once for each observation of DataSetA. I am doing this manually at the moment by changing a macro variable, which is the observation number of DataSetA: manually updating the observation number: 1, 2, 3, ...,n and manually pressing the SAS programme execution button each time. I would like to automate this simple process, but I don't know how. Could you please help me?&lt;BR /&gt;
&lt;BR /&gt;
I use PC SAS. I looked at some available tutorials and tips on SAS macros and functions, but I am overwhelmed by all the information for what I think is a really simple automation task. I have read that macros and functions cannot accommodate data steps, even the rather simple ones that I have in my ProgB (but I could be wrong). Any tips on what I can do?&lt;BR /&gt;
&lt;BR /&gt;
Algorithmically, all I want do is:&lt;BR /&gt;
&lt;BR /&gt;
Do i = 1 to n;&lt;BR /&gt;
     GetNextDataSetAObsvn(i);       /* puts DataSetA observation i in a table with only one observation */ &lt;BR /&gt;
     ExecuteProgB;                            /* executes lots of data steps, procs, etc on this single obsvn and updates DataSetB with the result */&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
But I don't know how to do this in PC SAS, even after trying for many hours!&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Ian.</description>
      <pubDate>Thu, 28 Apr 2011 15:07:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59380#M12855</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2011-04-28T15:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Automating execution of the same sas code n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59381#M12856</link>
      <description>Hi:&lt;BR /&gt;
  This is an excellent paper to get you started:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi28/056-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
  In particular, look at some of the later examples (Steps 7, 8, and 9), which show how to automate a DATA step and a PROC step in a macro program. Of course, you will have to understand steps 1 through 6 - -but the examples are quite good and very easy to understand.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 28 Apr 2011 15:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59381#M12856</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2011-04-28T15:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: Automating execution of the same sas code n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59382#M12857</link>
      <description>Hello Iank131,&lt;BR /&gt;
If I understood you correctly this is what you need (I used SASHELP.CLASS as an example);&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let dsn=SASHELP.CLASS;&lt;BR /&gt;
%macro a;&lt;BR /&gt;
  data _null_;&lt;BR /&gt;
    set &amp;amp;dsn obs=n end=e;&lt;BR /&gt;
    if e then call symputx('n',n);&lt;BR /&gt;
  run;&lt;BR /&gt;
  %do i=1 %to &amp;amp;n;&lt;BR /&gt;
    data _a;&lt;BR /&gt;
      set &amp;amp;dsn;&lt;BR /&gt;
      if _n_=&amp;amp;i;&lt;BR /&gt;
    run;&lt;BR /&gt;
    &lt;YOUR code="" processing="" _a="" here=""&gt;&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend a;&lt;BR /&gt;
%a&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR&lt;/YOUR&gt;</description>
      <pubDate>Thu, 28 Apr 2011 15:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59382#M12857</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-04-28T15:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Automating execution of the same sas code n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59383#M12858</link>
      <description>&amp;gt; Hi:&lt;BR /&gt;
&amp;gt;   This is an excellent paper to get you started:&lt;BR /&gt;
&amp;gt; tp://www2.sas.com/proceedings/sugi28/056-28.pdf&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Hi Cynthia, &lt;BR /&gt;
&lt;BR /&gt;
Many thanks for the paper reference. I worked through all the examples and learned a lot more from it than many other papers I looked at because this one was really step by step. Combining what I learned from this paper with the other reply I got, I have been able to solve my problem after more than a month of work on it! Thanks very much for your fast response and help!&lt;BR /&gt;
&lt;BR /&gt;
Best wishes,&lt;BR /&gt;
Ian.</description>
      <pubDate>Thu, 28 Apr 2011 21:45:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59383#M12858</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2011-04-28T21:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Automating execution of the same sas code n times</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59384#M12859</link>
      <description>&amp;gt; %let dsn=SASHELP.CLASS;&lt;BR /&gt;
&amp;gt; %macro a;&lt;BR /&gt;
&amp;gt;   data _null_;&lt;BR /&gt;
&amp;gt;   set &amp;amp;dsn nobs=n end=e;&lt;BR /&gt;
&amp;gt;   if e then call symputx('n',n);&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt;   %do i=1 %to &amp;amp;n;&lt;BR /&gt;
&amp;gt;   data _a;&lt;BR /&gt;
&amp;gt;     set &amp;amp;dsn;&lt;BR /&gt;
&amp;gt;   if _n_=&amp;amp;i;&lt;BR /&gt;
&amp;gt;   run;&lt;BR /&gt;
&amp;gt;   &lt;YOUR code="" processing="" _a="" here=""&gt;&lt;BR /&gt;
&amp;gt; %end;&lt;BR /&gt;
&amp;gt; %mend a;&lt;BR /&gt;
&amp;gt; %a&lt;BR /&gt;
&lt;BR /&gt;
Hi SPR,&lt;BR /&gt;
&lt;BR /&gt;
Many many thanks for your generous help on my problem! Combined with the paper Cynthia referred me to and your suggested code, it worked brilliantly! I solved a long-standing issue I had and learned a great deal more about macros.&lt;BR /&gt;
&lt;BR /&gt;
Thanks so much! and also for the how fast you responded!!&lt;BR /&gt;
Regards,&lt;BR /&gt;
Ian.&lt;/YOUR&gt;</description>
      <pubDate>Thu, 28 Apr 2011 21:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automating-execution-of-the-same-sas-code-n-times/m-p/59384#M12859</guid>
      <dc:creator>iank131</dc:creator>
      <dc:date>2011-04-28T21:49:16Z</dc:date>
    </item>
  </channel>
</rss>

