<?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 need help with do loop statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8393#M297</link>
    <description>I'm fairly new to SAS and very new to macros so I'm hoping I could get some help from fellow SAS users with much more knowledge and experience.  I've written code to do exactly what I need, however, the code is based on a single unique variable.  There are data sets within the code that are tied to the variable and some data sets merge based on the unique variable.  The problem I have is there are 193 more unique variables I need to run this same exact code for.  &lt;BR /&gt;
&lt;BR /&gt;
I've heard of using %do loops within macros but I can't seem to get started without losing my mind.  Would someone have some code for a beginner that would get me moving in the right direction?&lt;BR /&gt;
&lt;BR /&gt;
I'm wondering if I would need to make my code a macro in itself, then create the %do loop macro statement for the unique variable.  I can picture it in my head but I can't seem to put it into SAS code.  &lt;BR /&gt;
&lt;BR /&gt;
Any help is greatly appreciated!  Many thanks in advance.</description>
    <pubDate>Tue, 28 Sep 2010 16:44:00 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-09-28T16:44:00Z</dc:date>
    <item>
      <title>need help with do loop statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8393#M297</link>
      <description>I'm fairly new to SAS and very new to macros so I'm hoping I could get some help from fellow SAS users with much more knowledge and experience.  I've written code to do exactly what I need, however, the code is based on a single unique variable.  There are data sets within the code that are tied to the variable and some data sets merge based on the unique variable.  The problem I have is there are 193 more unique variables I need to run this same exact code for.  &lt;BR /&gt;
&lt;BR /&gt;
I've heard of using %do loops within macros but I can't seem to get started without losing my mind.  Would someone have some code for a beginner that would get me moving in the right direction?&lt;BR /&gt;
&lt;BR /&gt;
I'm wondering if I would need to make my code a macro in itself, then create the %do loop macro statement for the unique variable.  I can picture it in my head but I can't seem to put it into SAS code.  &lt;BR /&gt;
&lt;BR /&gt;
Any help is greatly appreciated!  Many thanks in advance.</description>
      <pubDate>Tue, 28 Sep 2010 16:44:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8393#M297</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-09-28T16:44:00Z</dc:date>
    </item>
    <item>
      <title>Re: need help with do loop statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8394#M298</link>
      <description>Have you looked at the SAS support &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  technical reference and conference papers, which provide much "free" information and programming techniques / methods.&lt;BR /&gt;
&lt;BR /&gt;
A Google advanced search such as the one below yields several candidate results:&lt;BR /&gt;
&lt;BR /&gt;
macro do loop processing site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
Also, if you are looking to "generate code" from source SAS variable and member names, consider also you may look at using DICTIONARY tables with PROC SQL (or their complimenting SAS views in SASHELP.Vxxxxxxx to work with generating SAS code based on known input data-values (variables, SAS library members, external file names).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search arguments, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
macro language documentation site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
dictionary tables site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
macro generate sas code site:sas.com</description>
      <pubDate>Tue, 28 Sep 2010 16:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8394#M298</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-09-28T16:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: need help with do loop statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8395#M299</link>
      <description>I'm a fairly seasoned SAS user and much familiar with macros, so I am hoping I could help out fellow SAS users, but can't. I've heard of *mind reading* and I can't seem to perform it effectively to scan OP's. Any help is greatly appreciated! Many thanks in advance. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Seriously, below is my best guess, which may be totally different from what you are trying to do:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   /* create a data set with 194 vars */&lt;BR /&gt;
   data one;&lt;BR /&gt;
     retain v001-v194 1;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
   /* create the data set, some, to be merged in */&lt;BR /&gt;
   data some;&lt;BR /&gt;
     retain v001-v194 1 s 2;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
   /* merge one and some matching on each of v001, v002, ..., v194,&lt;BR /&gt;
      creating datasets merged001, merged002, ... merged194, respectively */&lt;BR /&gt;
   %macro merge(n=);&lt;BR /&gt;
     %local out v s;&lt;BR /&gt;
     %let out=merged&amp;amp;n;&lt;BR /&gt;
     %let v = v&amp;amp;n;&lt;BR /&gt;
     %let s = s&amp;amp;n; &lt;BR /&gt;
     data &amp;amp;out;&lt;BR /&gt;
       merge one some(keep=&amp;amp;v s rename=(s=&amp;amp;s));&lt;BR /&gt;
       by &amp;amp;v;&lt;BR /&gt;
       keep &amp;amp;v &amp;amp;s;&lt;BR /&gt;
     run;&lt;BR /&gt;
   %mend  merge;&lt;BR /&gt;
   %macro doMerges(upto=);&lt;BR /&gt;
     %local i;&lt;BR /&gt;
     %do i = 1 %to &amp;amp;upto;&lt;BR /&gt;
       %merge(n=&amp;amp;i)&lt;BR /&gt;
     %end;&lt;BR /&gt;
   %mend  doMerges;&lt;BR /&gt;
&lt;BR /&gt;
   %doMerges(upto=194)&lt;BR /&gt;
&lt;BR /&gt;
   /* check */&lt;BR /&gt;
   proc print data=merged194 noobs;&lt;BR /&gt;
   run;&lt;BR /&gt;
   /* on lst&lt;BR /&gt;
   v194    s194&lt;BR /&gt;
     1       2&lt;BR /&gt;
   */&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 28 Sep 2010 17:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8395#M299</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-09-28T17:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: need help with do loop statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8396#M300</link>
      <description>Here's the %DO loop doc.  Hopefully this will help.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543543.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543543.htm&lt;/A&gt;</description>
      <pubDate>Mon, 13 Dec 2010 15:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/need-help-with-do-loop-statement/m-p/8396#M300</guid>
      <dc:creator>PatrickG</dc:creator>
      <dc:date>2010-12-13T15:39:22Z</dc:date>
    </item>
  </channel>
</rss>

