<?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: How to change execute order in SAS DO loop. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/456272#M115553</link>
    <description>&lt;P&gt;Thanks guys ! both methods are working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Apr 2018 08:48:16 GMT</pubDate>
    <dc:creator>Pysiek</dc:creator>
    <dc:date>2018-04-22T08:48:16Z</dc:date>
    <item>
      <title>How to change execute order in SAS DO loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/455860#M115392</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro with do loop inside. I would like to change order of executing do loop. I need to run first proc report (where = _trt =1)&amp;nbsp; five times (for each age_n group) and then execute second proc report five times also for each age_n group. Dummy code is presented below. Thanks for your help !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Order of proc report should be like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;_trt 1 , age_n =1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt 1 , age_n =2&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt 1 , age_n =3&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt 1 , age_n =4&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt 1 , age_n =5&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt&amp;nbsp;2 , age_n =1&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt&amp;nbsp;2&amp;nbsp;, age_n =2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt&amp;nbsp;2&amp;nbsp;, age_n =3&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt&amp;nbsp;2&amp;nbsp;, age_n =4&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;_trt&amp;nbsp;2&amp;nbsp;, age_n =5&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;do i = 1 to 5;&lt;BR /&gt;y = i;&lt;BR /&gt;_trt=1;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;do i = 1 to 5;&lt;BR /&gt;y = i;&lt;BR /&gt;_trt=2;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data c;&lt;BR /&gt;set a b;&lt;BR /&gt;rename i = age_n;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select count(distinct age_n) into: n from c;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;options spool mprint mlogic symbolgen;&lt;/P&gt;&lt;P&gt;%macro test;&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc report data=c (where=(_trt=1 and age_n=&amp;amp;i)) headline missing nowindows split='|';&lt;BR /&gt;by age_n;&lt;BR /&gt;column age_n y _trt;&lt;BR /&gt;define _trt / display;&lt;BR /&gt;define age_n / display;&lt;BR /&gt;define y / display;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc report data=c (where=(_trt=2 and age_n=&amp;amp;i)) headline missing nowindows split='|';&lt;BR /&gt;by age_n;&lt;BR /&gt;column age_n y _trt;&lt;BR /&gt;define _trt / display;&lt;BR /&gt;define nage / display;&lt;BR /&gt;define y / display;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 09:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/455860#M115392</guid>
      <dc:creator>Pysiek</dc:creator>
      <dc:date>2018-04-20T09:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to change execute order in SAS DO loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/455867#M115394</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data c;
do _trt = 1 to 2;
  do age_n = 1 to 5;
    y = age_n;
    output;
  end;
end;
run;

proc report data=c headline missing nowindows split='|';
by _trt age_n;
column age_n y _trt;
define _trt / display;
define age_n / display;
define y / display;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No macro needed at all.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 10:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/455867#M115394</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-20T10:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to change execute order in SAS DO loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/455869#M115395</link>
      <description>&lt;P&gt;TRY This one. I have amended a bit more.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
do i = 1 to 5;
y = i;
_trt=1;
output;
end;
run;

 

data b;
do i = 1 to 5;
y = i;
_trt=2;
output;
end;
run;


data have;
set a b;
rename i = age_n;
run;

proc sort data=have; by _trt age_n ; run;

proc sql noprint;
select count(*) into: n from have;
quit;


options spool mprint mlogic symbolgen;

%macro test;

%do i=1 %to &amp;amp;n;
		proc sql noconstdatetime noprint;
			select _trt, age_n  into :trt, :age
            from have 
            where monotonic() between &amp;amp;i and &amp;amp;i  
        ;quit;


proc report data=have (where=(_trt=&amp;amp;trt and age_n=&amp;amp;age)) headline missing nowindows split='|';
by _trt age_n;
column age_n y _trt;
define _trt / display;
define age_n / display;
define y / display;
run;

%end;
 
%mend;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 10:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/455869#M115395</guid>
      <dc:creator>emrancaan</dc:creator>
      <dc:date>2018-04-20T10:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to change execute order in SAS DO loop.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/456272#M115553</link>
      <description>&lt;P&gt;Thanks guys ! both methods are working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Apr 2018 08:48:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-execute-order-in-SAS-DO-loop/m-p/456272#M115553</guid>
      <dc:creator>Pysiek</dc:creator>
      <dc:date>2018-04-22T08:48:16Z</dc:date>
    </item>
  </channel>
</rss>

