<?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: DO LOOP for several procedure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247809#M46472</link>
    <description>&lt;P&gt;This could be the template code for your intended double %DO loop (as an example with 2x2 "section_part" variables):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id_order enter section_1_part_1 section_1_part_2 section_2_part_1 section_2_part_2; 
cards;
1 1 5 12 5 6
2 7 20 7 20 21
3 11 15 11 15 16
4 18 22 20 50 51
5 22 43 22 30 31
6 25 100 50 100 101
run;


%macro comp;
%local i j;
%do i=1 %to 2;
  %do j=1 %to 2;
    data want;
    set have;
    retain lag_exit;
    if lag_exit &amp;gt; enter then delete;
    else lag_exit = section_&amp;amp;i._part_&amp;amp;j;
    run;

    proc summary data=want; 
    var section_&amp;amp;i._part_&amp;amp;j;
    output out=table(drop=_:)
    mean=mean_exit&amp;amp;i._&amp;amp;j;
    run;

    %if &amp;amp;i=1 and &amp;amp;j=1 %then %do;
      data allmeans;
      set table;
      run;
    %end;
    %else %do;
      data allmeans;
      set allmeans;
      set table;
      run;
    %end;
  %end;
%end;
%mend comp;
%comp

proc print data=allmeans;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Feb 2016 18:00:13 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2016-02-03T18:00:13Z</dc:date>
    <item>
      <title>DO LOOP for several procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247798#M46468</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My data has variable exit1, exit2 ....&lt;/P&gt;
&lt;P&gt;(The actual name in the form section_&amp;amp;i_part_&amp;amp;j so I will have to do double Do loop)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to run a procedure for all exit variables. It should be like&lt;/P&gt;
&lt;P&gt;do n=1 to 100;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;proc means; output out=table&amp;amp;n...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I want to merge all table&amp;amp;n into 1 summary file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me with that?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; input id_order enter exit1 exit2 exit3; 
cards;
1 1 5 12 5
2 7 20 7 20
3 11 15 11 15
4 18 22 20 50
5 22 43 22 30
6 25 100 50 100
run;

proc sort data=have;
by enter;
run;
&lt;BR /&gt;*------DO LOOP n=1 to 3-----------------------------------------------------;
*%let n=1;

data want&amp;amp;n;
	set have;
	retain lag_exit;
	if lag_exit &amp;gt; enter then delete;
	else lag_exit = exit&amp;amp;n;
run;

proc means data=want&amp;amp;n; 
var exit&amp;amp;n;
output out=table&amp;amp;n
mean=mean_exit&amp;amp;n;
run;

*I WANT TO MERGE ALL 3 MEAN OUTPUT INTO 1 FILE. THIS FILE WILL HAVE 3 VAIRABLEs: mean_exit1 mean_exit2 mean_exit3;&lt;BR /&gt;&lt;BR /&gt;****************final code*********************;&lt;BR /&gt;&lt;BR /&gt;%macro test;&lt;BR /&gt;%do n=1 %to 3;&lt;BR /&gt;&lt;BR /&gt; data want&amp;amp;n;&lt;BR /&gt; set have;&lt;BR /&gt; retain lag_exit;&lt;BR /&gt; if lag_exit &amp;gt; enter then delete;&lt;BR /&gt; else lag_exit = exit&amp;amp;n;&lt;BR /&gt; run;&lt;BR /&gt;&lt;BR /&gt; proc means data=want&amp;amp;n; &lt;BR /&gt; var exit&amp;amp;n;&lt;BR /&gt; output out=table (drop=_:)&lt;BR /&gt; mean=mean_exit&amp;amp;n;&lt;BR /&gt; run;&lt;BR /&gt;&lt;BR /&gt; data table; set table;&lt;BR /&gt; t=1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; %if &amp;amp;n=1 %then %do;&lt;BR /&gt; data all; set table;run;&lt;BR /&gt; %end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; %else %do;&lt;BR /&gt; proc sql;&lt;BR /&gt; create table all&lt;BR /&gt; as select * from all left join table&lt;BR /&gt; on all.t=table.t;&lt;BR /&gt; quit;&lt;BR /&gt; %end;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;&lt;BR /&gt;%test;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 00:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247798#M46468</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-04T00:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP for several procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247799#M46469</link>
      <description>&lt;P&gt;For your sample data you could try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro comp;
%local n;
%do n=1 %to 3;
  data want&amp;amp;n;
  set have;
  retain lag_exit;
  if lag_exit &amp;gt; enter then delete;
  else lag_exit = exit&amp;amp;n;
  run;

  proc summary data=want&amp;amp;n; 
  var exit&amp;amp;n;
  output out=table&amp;amp;n
  mean=mean_exit;
  run;

  proc append base=allmeans0 new=table&amp;amp;n(drop=_:);
  run;
%end;
%mend comp;
%comp

proc transpose data=allmeans0 out=allmeans(drop=_:) prefix=mean_exit;
run;

proc print data=allmeans;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: If you don't really need all those WANT1, WANT2, ... and TABLE1, TABLE2, ... datasets, you could simply omit all the &amp;amp;n suffixes, except those in &lt;FONT face="courier new,courier"&gt;exit&amp;amp;n&lt;/FONT&gt;. Also, please be aware that PROC APPEND is cumulative if you run the above code more than once. To avoid this effect you could&amp;nbsp;replace the PROC APPEND step with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  %if &amp;amp;n=1 %then %do;
    data allmeans0;
    set table&amp;amp;n(drop=_:);
    run;
  %end;
  %else %do;
    proc append base=allmeans0 new=table&amp;amp;n(drop=_:);
    run;
  %end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 17:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247799#M46469</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-03T17:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP for several procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247802#M46471</link>
      <description>&lt;P&gt;If you have already run the existing code, and now need to combine TABLE1 through TABLE100 after the fact, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro combine (n=100);&lt;/P&gt;
&lt;P&gt;%local i;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;set table&amp;amp;i;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;%mend combine;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may get messages due to the fact that the output data sets from PROC MEANS all contain variables _TYPE_ and _FREQ_.&amp;nbsp; Since you don't need those variables, you can ignore the messages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2016 17:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247802#M46471</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-03T17:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP for several procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247809#M46472</link>
      <description>&lt;P&gt;This could be the template code for your intended double %DO loop (as an example with 2x2 "section_part" variables):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id_order enter section_1_part_1 section_1_part_2 section_2_part_1 section_2_part_2; 
cards;
1 1 5 12 5 6
2 7 20 7 20 21
3 11 15 11 15 16
4 18 22 20 50 51
5 22 43 22 30 31
6 25 100 50 100 101
run;


%macro comp;
%local i j;
%do i=1 %to 2;
  %do j=1 %to 2;
    data want;
    set have;
    retain lag_exit;
    if lag_exit &amp;gt; enter then delete;
    else lag_exit = section_&amp;amp;i._part_&amp;amp;j;
    run;

    proc summary data=want; 
    var section_&amp;amp;i._part_&amp;amp;j;
    output out=table(drop=_:)
    mean=mean_exit&amp;amp;i._&amp;amp;j;
    run;

    %if &amp;amp;i=1 and &amp;amp;j=1 %then %do;
      data allmeans;
      set table;
      run;
    %end;
    %else %do;
      data allmeans;
      set allmeans;
      set table;
      run;
    %end;
  %end;
%end;
%mend comp;
%comp

proc print data=allmeans;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2016 18:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247809#M46472</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-02-03T18:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: DO LOOP for several procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247886#M46503</link>
      <description>&lt;P&gt;That code teaches me a lot!&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2016 00:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-LOOP-for-several-procedure/m-p/247886#M46503</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-04T00:28:55Z</dc:date>
    </item>
  </channel>
</rss>

