<?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: Help in Macro loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391137#M93895</link>
    <description>&lt;P&gt;Are you trying to split data into subsets of 1000 rows?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I don't think you need a macro for that.&lt;/P&gt;</description>
    <pubDate>Sun, 27 Aug 2017 18:00:53 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-08-27T18:00:53Z</dc:date>
    <item>
      <title>Help in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391134#M93893</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This macro works fine. I am trying to create a macro and pass on the ID to rest of the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WANT (keep=id);&lt;BR /&gt;set have nobs=_nobs_;&lt;BR /&gt;count = ceil(_n_ / 1000);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset want has column called ID( 6500 ids).Created a variable called count, setting to 1000 ids in each count.&lt;/P&gt;&lt;P&gt;Created a global variable Check.&lt;/P&gt;&lt;P&gt;This macro works fine when the loop is 1 to 7 (each check contains 1000), but If I increment from 7 to 10, the rest of the 3 increments (8,9,10) gets repeated (having the same set of ids from the last iterations).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help here. I wanna tell the macro to stop working &amp;nbsp;when it reaches the last obs in the dataset WANT. Iteration J&amp;nbsp;should stop looping. When it reaches the last observation , the iteration also should stop. if its 7 or 8 then stop till 7 or 8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dont want to change the iterations from 10 to 7. Because I want to use the same program again &amp;amp; my next dataset have more ids( more than 8000). &amp;nbsp;I dont want to keep changing the numbers in interation.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro tests;&lt;BR /&gt;%do j = 1 % to 10 ;&lt;BR /&gt;%global check_&amp;amp;j;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select id into: check separated by ","&lt;BR /&gt;from WANT&lt;BR /&gt;where count = &amp;amp;j;&lt;BR /&gt;quit;&lt;BR /&gt;%let check_&amp;amp;j = (&amp;amp;check);&lt;BR /&gt;%put check_&amp;amp;j= &amp;amp;&amp;amp;check_&amp;amp;j;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%create_tests;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 17:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391134#M93893</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-27T17:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391137#M93895</link>
      <description>&lt;P&gt;Are you trying to split data into subsets of 1000 rows?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I don't think you need a macro for that.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 18:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391137#M93895</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-27T18:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391141#M93898</link>
      <description>&lt;P&gt;I am trying to pass ids to Oracle SQL in where condition.&lt;/P&gt;&lt;P&gt;Proc sql;&lt;/P&gt;&lt;P&gt;connect to oracle(user=&amp;amp;userid. password=&amp;amp;passwd. path= preserve_comments);&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 18:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391141#M93898</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-27T18:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391142#M93899</link>
      <description>&lt;P&gt;OK... I still probably wouldn't use a macro, but would use a data step with a single loop through. At each 1000 or end then you create the macro variable that you've been collecting until the end.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a start, I don't have more time to tweak this but think it works the way you want. This is fully dynamic based on your dataset and size. You could wrap it in a macro I suppose.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create a sample data set;
data have;
    do i=1 to 7000;
        x=rand('bernoulli', 0.4);
        output;
    end;
run;

*Set group size;
%let group_size = 1000;

*Creates a data set, but not required can be a data _null_ data step;
data want;

    set have end=_eof nobs=_nobs;
    length list_names $32000.;
    retain group 0 list_names;

    prev_group=group;
    
    if mod(_n_, &amp;amp;group_size)=0 then group+1;
    
    if group ne prev_group or _eof then do;
        if _eof then list_names = catx(", ", list_names, put(x, 8.2));
        call symputx("list"||put(group, z2.), list_names, 'g');
        call missing(list_names);
    end;

        list_names = catx(", ", list_names, put(x, 8.2));

    
run;

%put &amp;amp;list01;
%put &amp;amp;list04;
    
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 18:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391142#M93899</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-27T18:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391144#M93901</link>
      <description>Thank you, I will try this!</description>
      <pubDate>Sun, 27 Aug 2017 18:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391144#M93901</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-08-27T18:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391161#M93908</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/86703"&gt;@Kalai2008&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If you explain us a bit better what you have and what you're trying to achieve then we can may-be provide better answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e: You don't need to count observations in SAS tables as the number of observations is a data set attribute. So there is no need to have a full pass through your data for every single iteration of your macro loop.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Aug 2017 23:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-in-Macro-loop/m-p/391161#M93908</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-08-27T23:24:56Z</dc:date>
    </item>
  </channel>
</rss>

