<?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 challenge:  groups of 3 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68808#M14928</link>
    <description>the %gen() macro and variants has been posted before&lt;BR /&gt;
Objective is to generate a pattern, subject to cycling numbers, so can simply be 1 2 3     or generate 10 11 12 .&lt;BR /&gt;
 &lt;BR /&gt;
What is confusing me here is the break in groups of 3.&lt;BR /&gt;
%put NOTE- 1 2 3;&lt;BR /&gt;
%put note- 4 5 6;&lt;BR /&gt;
%put note- 7 8 9 ;&lt;BR /&gt;
demonstrates one way to place text in the log with NOTE coloring, but without the NOTE: prefix.&lt;BR /&gt;
Was that what "edilts" wanted?&lt;BR /&gt;
&lt;BR /&gt;
More effective is a data step, like[pre]data _null_ ;&lt;BR /&gt;
put 'NOTE- 1 2 3';&lt;BR /&gt;
put 'NOTE- 4 5 6';&lt;BR /&gt;
put 'NOTE- 7 8 9' ;&lt;BR /&gt;
run;[/pre]which produces the log[pre]113  data _null_ ;&lt;BR /&gt;
114  put 'NOTE- 1 2 3';&lt;BR /&gt;
115  put 'NOTE- 4 5 6';&lt;BR /&gt;
116  put 'NOTE- 7 8 9' ;&lt;BR /&gt;
117  run;&lt;BR /&gt;
&lt;BR /&gt;
      1 2 3&lt;BR /&gt;
      4 5 6&lt;BR /&gt;
      7 8 9&lt;BR /&gt;
NOTE: DATA statement used (Total process time):[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
ymmv&lt;BR /&gt;
peterC</description>
    <pubDate>Tue, 31 Aug 2010 15:26:26 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-08-31T15:26:26Z</dc:date>
    <item>
      <title>macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68804#M14924</link>
      <description>%macro RunMP;&lt;BR /&gt;
  %do RunMP = 1 %to 5;&lt;BR /&gt;
    %let p1=%eval(&amp;amp;RunMP);&lt;BR /&gt;
    %let p2=%eval(&amp;amp;RunMP+1);&lt;BR /&gt;
    %let p3=%eval(&amp;amp;RunMP+2);&lt;BR /&gt;
    %put &amp;amp;p1 &amp;amp;p2 &amp;amp;p3;&lt;BR /&gt;
  %end;&lt;BR /&gt;
%mend; %RunMP *;&lt;BR /&gt;
&lt;BR /&gt;
I've tried everything I can think of... I need distinct sets of three consecutive numbers, so the log output should be&lt;BR /&gt;
1   2   3&lt;BR /&gt;
4   5   6&lt;BR /&gt;
7   8   9&lt;BR /&gt;
10 11 12&lt;BR /&gt;
13 14 15&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts would be appreciated.</description>
      <pubDate>Tue, 31 Aug 2010 14:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68804#M14924</guid>
      <dc:creator>edilts</dc:creator>
      <dc:date>2010-08-31T14:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68805#M14925</link>
      <description>Try this (not tested)&lt;BR /&gt;
&lt;BR /&gt;
%macro RunMP;&lt;BR /&gt;
%let p1=1;&lt;BR /&gt;
%do RunMP = 1 %to 5;&lt;BR /&gt;
%let p2=%eval(&amp;amp;p1+1);&lt;BR /&gt;
%let p3=%eval(&amp;amp;p2+1);&lt;BR /&gt;
%put &amp;amp;p1 &amp;amp;p2 &amp;amp;p3;&lt;BR /&gt;
%let p1=%eval(&amp;amp;p3+1);&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend; %RunMP *;</description>
      <pubDate>Tue, 31 Aug 2010 14:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68805#M14925</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-08-31T14:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68806#M14926</link>
      <description>Hi:&lt;BR /&gt;
  My question is WHERE do you need to have distinct sets of three consecutive numbers??? What good will the numbers in the log do??? Is this part of a bigger program or a different problem???&lt;BR /&gt;
 &lt;BR /&gt;
  At any rate, there's nothing wrong with changing the value of &amp;amp;RUNMP inside the %DO loop. So if you changed the ending value to 15&lt;BR /&gt;
[pre]&lt;BR /&gt;
%do RunMP = 1 %to 15;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                &lt;BR /&gt;
...Since, there's nothing wrong with "resetting" the value of &amp;amp;RUNMP -- and, since the %DO loop will automatically increment by 1...the simplest thing to do after your %PUT is to reset the value of &amp;amp;RUNMP to be equal to the value of &amp;amp;P3:&lt;BR /&gt;
[pre]&lt;BR /&gt;
 %put &amp;amp;p1 &amp;amp;p2 &amp;amp;p3;&lt;BR /&gt;
 %let RunMP = &amp;amp;p3;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
              &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 31 Aug 2010 14:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68806#M14926</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-08-31T14:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68807#M14927</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
You should use the %by option of the %do loop. Your macro becomes:&lt;BR /&gt;
&lt;BR /&gt;
%macro RunMP;&lt;BR /&gt;
%do RunMP = 1 %to 5 %by 3;&lt;BR /&gt;
%let p1=%eval(&amp;amp;RunMP);&lt;BR /&gt;
%let p2=%eval(&amp;amp;RunMP+1);&lt;BR /&gt;
%let p3=%eval(&amp;amp;RunMP+2);&lt;BR /&gt;
%put &amp;amp;p1 &amp;amp;p2 &amp;amp;p3;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend; %RunMP *;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You should also keep in mind that if you have a number of elements to display which is not a multiple of 3, you could see unresolved macro-variables displayed (text '&amp;amp;p1', '&amp;amp;p2' or '&amp;amp;p3' ) in your log... So you should check that each macro-variable you want to display exists prior including its reference in the %put statement.&lt;BR /&gt;
&lt;BR /&gt;
I hope it helps.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Florent</description>
      <pubDate>Tue, 31 Aug 2010 14:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68807#M14927</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2010-08-31T14:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68808#M14928</link>
      <description>the %gen() macro and variants has been posted before&lt;BR /&gt;
Objective is to generate a pattern, subject to cycling numbers, so can simply be 1 2 3     or generate 10 11 12 .&lt;BR /&gt;
 &lt;BR /&gt;
What is confusing me here is the break in groups of 3.&lt;BR /&gt;
%put NOTE- 1 2 3;&lt;BR /&gt;
%put note- 4 5 6;&lt;BR /&gt;
%put note- 7 8 9 ;&lt;BR /&gt;
demonstrates one way to place text in the log with NOTE coloring, but without the NOTE: prefix.&lt;BR /&gt;
Was that what "edilts" wanted?&lt;BR /&gt;
&lt;BR /&gt;
More effective is a data step, like[pre]data _null_ ;&lt;BR /&gt;
put 'NOTE- 1 2 3';&lt;BR /&gt;
put 'NOTE- 4 5 6';&lt;BR /&gt;
put 'NOTE- 7 8 9' ;&lt;BR /&gt;
run;[/pre]which produces the log[pre]113  data _null_ ;&lt;BR /&gt;
114  put 'NOTE- 1 2 3';&lt;BR /&gt;
115  put 'NOTE- 4 5 6';&lt;BR /&gt;
116  put 'NOTE- 7 8 9' ;&lt;BR /&gt;
117  run;&lt;BR /&gt;
&lt;BR /&gt;
      1 2 3&lt;BR /&gt;
      4 5 6&lt;BR /&gt;
      7 8 9&lt;BR /&gt;
NOTE: DATA statement used (Total process time):[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
ymmv&lt;BR /&gt;
peterC</description>
      <pubDate>Tue, 31 Aug 2010 15:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68808#M14928</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-08-31T15:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68809#M14929</link>
      <description>I always like an opportunity to use PROC PLAN.  Perhaps a bit of overkill but it may pique your interest in this very useful procedure.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%let p=3;&lt;BR /&gt;
%let r=15;&lt;BR /&gt;
&lt;BR /&gt;
proc plan ordered;&lt;BR /&gt;
   ods output plan=plan;&lt;BR /&gt;
   factors r=&amp;amp;r p=&amp;amp;p of %sysevalF(&amp;amp;r*&amp;amp;p,I) cyclic(1 to &amp;amp;p)&amp;amp;p;&lt;BR /&gt;
   run;&lt;BR /&gt;
   quit;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   set plan;&lt;BR /&gt;
   if _n_ eq 1 &lt;BR /&gt;
      then putlog 'NOTE: ' @;&lt;BR /&gt;
      else putlog 'NOTE- ' @;&lt;BR /&gt;
   put (p:) (+1 3.);&lt;BR /&gt;
   run;&lt;BR /&gt;
  &lt;BR /&gt;
&lt;B&gt;NOTE:    1   2   3&lt;BR /&gt;
         4   5   6&lt;BR /&gt;
         7   8   9&lt;BR /&gt;
        10  11  12&lt;BR /&gt;
        13  14  15&lt;BR /&gt;
        16  17  18&lt;BR /&gt;
        19  20  21&lt;BR /&gt;
        22  23  24&lt;BR /&gt;
        25  26  27&lt;BR /&gt;
        28  29  30&lt;BR /&gt;
        31  32  33&lt;BR /&gt;
        34  35  36&lt;BR /&gt;
        37  38  39&lt;BR /&gt;
        40  41  42&lt;BR /&gt;
        43  44  45&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 31 Aug 2010 16:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68809#M14929</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-08-31T16:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro challenge:  groups of 3</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68810#M14930</link>
      <description>Thank you for the assistance - I used the method described by Florent and it worked perfectly.&lt;BR /&gt;
&lt;BR /&gt;
My code was just an example; I didn't actually need the numbers in the log, I needed them to plug into another macro loop which was nested inside that one.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Erik

Message was edited by: edilts</description>
      <pubDate>Tue, 31 Aug 2010 16:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-challenge-groups-of-3/m-p/68810#M14930</guid>
      <dc:creator>edilts</dc:creator>
      <dc:date>2010-08-31T16:27:53Z</dc:date>
    </item>
  </channel>
</rss>

