<?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: Slide a list into smaller list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836422#M330711</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let my_list = min0 min1 min2 min3 min4 min5;&lt;BR /&gt;&lt;BR /&gt;/* Outer loop macro */&lt;BR /&gt;%MACRO OUTER_LOOP;&lt;BR /&gt;   %global list_of_3; %global j;&lt;BR /&gt;   %local k; &lt;BR /&gt;   %let j=1; /* Initializing a global variable j to 1 */&lt;BR /&gt;   /* Looping till j &amp;lt; size of &amp;amp;my_list */&lt;BR /&gt;   %do %while (&amp;amp;j &amp;lt;= %sysfunc(countw(&amp;amp;my_list)));&lt;BR /&gt;        %let list_of_3=;&lt;BR /&gt;		/* Looping to create &amp;amp;list_of_3 */&lt;BR /&gt;		%do k=&amp;amp;j. %to (&amp;amp;j.+2);&lt;BR /&gt;		 	%let list_of_3 = &amp;amp;list_of_3 %scan("&amp;amp;my_list", &amp;amp;k, " ");  &lt;BR /&gt;   		%end;&lt;BR /&gt;		%put Inital Value of j = &amp;amp;j.; &lt;BR /&gt;	    %put List in Outer Loop= &amp;amp;list_of_3.;&lt;BR /&gt;		%INNER_LOOP; /* calling inner loop macro for analysis */&lt;BR /&gt;		%let j=%eval(&amp;amp;j.+3); /* Updating j */&lt;BR /&gt;		%put Updated Value of j = &amp;amp;j.; &lt;BR /&gt;	%end;   &lt;BR /&gt;%mend OUTER_LOOP;&lt;BR /&gt;&lt;BR /&gt;/* Inner loop macro */&lt;BR /&gt;%MACRO INNER_LOOP;&lt;BR /&gt;	%local l;&lt;BR /&gt;	 %put List in Inner Loop= &amp;amp;list_of_3.;&lt;BR /&gt;	%do l=1 %to %sysfunc(countw(&amp;amp;list_of_3));&lt;BR /&gt;		*MY ANALYSIS;&lt;BR /&gt;	%end;&lt;BR /&gt;%MEND INNER_LOOP;&lt;BR /&gt;&lt;BR /&gt;%OUTER_LOOP;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
    <pubDate>Sun, 02 Oct 2022 19:47:53 GMT</pubDate>
    <dc:creator>SubbuPaz</dc:creator>
    <dc:date>2022-10-02T19:47:53Z</dc:date>
    <item>
      <title>Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836415#M330706</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a long list of factors and I need to analyze 3 factors at a time.&lt;/P&gt;
&lt;P&gt;The idea is that the Outer_loop will slide out 3 factors and then the Inner_Loop will do the analysis.&lt;/P&gt;
&lt;P&gt;This code below move element 1 by 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I take group of 3?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let my_list = min0 min1 min2 min3 min4 min5;

%MACRO OUTER_LOOP;
	%do i=1 %to %sysfunc(countw(&amp;amp;my_list));
	%let list_of_3=%scan(&amp;amp;my_list,&amp;amp;i);
	%put &amp;amp;list_of_3;
/*
		%MACRO INNER_LOOP;
			%do J=1 %to %sysfunc(countw(&amp;amp;list_of_3));
			*MY ANALYSIS;
			%end;
		%MEND;

		%MACRO INNER_LOOP; *Run inner loop;
*/
	%end;
%mend;

%OUTER_LOOP;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Oct 2022 19:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836415#M330706</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-02T19:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836419#M330710</link>
      <description>&lt;P&gt;Use an additional delimiter:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let my_list = min0 min1 min2|min3 min4 min5;

%MACRO OUTER_LOOP;
	%do i=1 %to %sysfunc(countw(&amp;amp;my_list,|));
	%let list_of_3=%scan(&amp;amp;my_list,&amp;amp;i,|);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or use a different increment:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let my_list = min0 min1 min2 min3 min4 min5;

%MACRO OUTER_LOOP;
	%do i=1 %to %sysfunc(countw(&amp;amp;my_list)) %by 3;
	%let list_of_3=%scan(&amp;amp;my_list,&amp;amp;i) %scan(&amp;amp;my_list,%eval(&amp;amp;i+1)) %scan(&amp;amp;my_list,%eval(&amp;amp;i+2));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Oct 2022 19:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836419#M330710</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-10-02T19:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836422#M330711</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let my_list = min0 min1 min2 min3 min4 min5;&lt;BR /&gt;&lt;BR /&gt;/* Outer loop macro */&lt;BR /&gt;%MACRO OUTER_LOOP;&lt;BR /&gt;   %global list_of_3; %global j;&lt;BR /&gt;   %local k; &lt;BR /&gt;   %let j=1; /* Initializing a global variable j to 1 */&lt;BR /&gt;   /* Looping till j &amp;lt; size of &amp;amp;my_list */&lt;BR /&gt;   %do %while (&amp;amp;j &amp;lt;= %sysfunc(countw(&amp;amp;my_list)));&lt;BR /&gt;        %let list_of_3=;&lt;BR /&gt;		/* Looping to create &amp;amp;list_of_3 */&lt;BR /&gt;		%do k=&amp;amp;j. %to (&amp;amp;j.+2);&lt;BR /&gt;		 	%let list_of_3 = &amp;amp;list_of_3 %scan("&amp;amp;my_list", &amp;amp;k, " ");  &lt;BR /&gt;   		%end;&lt;BR /&gt;		%put Inital Value of j = &amp;amp;j.; &lt;BR /&gt;	    %put List in Outer Loop= &amp;amp;list_of_3.;&lt;BR /&gt;		%INNER_LOOP; /* calling inner loop macro for analysis */&lt;BR /&gt;		%let j=%eval(&amp;amp;j.+3); /* Updating j */&lt;BR /&gt;		%put Updated Value of j = &amp;amp;j.; &lt;BR /&gt;	%end;   &lt;BR /&gt;%mend OUTER_LOOP;&lt;BR /&gt;&lt;BR /&gt;/* Inner loop macro */&lt;BR /&gt;%MACRO INNER_LOOP;&lt;BR /&gt;	%local l;&lt;BR /&gt;	 %put List in Inner Loop= &amp;amp;list_of_3.;&lt;BR /&gt;	%do l=1 %to %sysfunc(countw(&amp;amp;list_of_3));&lt;BR /&gt;		*MY ANALYSIS;&lt;BR /&gt;	%end;&lt;BR /&gt;%MEND INNER_LOOP;&lt;BR /&gt;&lt;BR /&gt;%OUTER_LOOP;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Oct 2022 19:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836422#M330711</guid>
      <dc:creator>SubbuPaz</dc:creator>
      <dc:date>2022-10-02T19:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836425#M330712</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a long list of factors and I need to analyze 3 factors at a time.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you need all possible 3-element subsets of the list of factors? Then see if this could serve as a template for your "outer loop":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let my_list = min0 min1 min2 min3 min4 min5;

%macro comb3(list);
%local i j k n;
%let n=%sysfunc(countw(&amp;amp;list));
%put All comb(&amp;amp;n,3)=%sysfunc(comb(&amp;amp;n,3)) combinations of three elements of {&amp;amp;list}:;
%do i=1 %to &amp;amp;n-2;
  %do j=&amp;amp;i+1 %to &amp;amp;n-1;
    %do k=&amp;amp;j+1 %to &amp;amp;n;
      %put %scan(&amp;amp;list,&amp;amp;i) %scan(&amp;amp;list,&amp;amp;j) %scan(&amp;amp;list,&amp;amp;k);
    %end;
  %end;
%end;
%mend comb3;

%comb3(&amp;amp;my_list)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;All comb(6,3)=20 combinations of three elements of {min0 min1 min2 min3 min4 min5}:
min0 min1 min2
min0 min1 min3
min0 min1 min4
min0 min1 min5
min0 min2 min3
min0 min2 min4
min0 min2 min5
min0 min3 min4
min0 min3 min5
min0 min4 min5
min1 min2 min3
min1 min2 min4
min1 min2 min5
min1 min3 min4
min1 min3 min5
min1 min4 min5
min2 min3 min4
min2 min3 min5
min2 min4 min5
min3 min4 min5&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Oct 2022 20:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836425#M330712</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-10-02T20:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836431#M330713</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi, If you need all possible 3-element subsets of the list of factors like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;asked in his post, you could modify the below line in my suggested code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let j=%eval(&amp;amp;j.+1); /* Updating j */&lt;/PRE&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Oct 2022 20:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836431#M330713</guid>
      <dc:creator>SubbuPaz</dc:creator>
      <dc:date>2022-10-02T20:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836455#M330723</link>
      <description>&lt;P&gt;Note that %EVAL() is not need, the macro processor will already evaluate the second parameter to %SCAN() with %EVAL().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list_of_3=%scan(&amp;amp;my_list,&amp;amp;i) %scan(&amp;amp;my_list,&amp;amp;i+1) %scan(&amp;amp;my_list,&amp;amp;i+2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also it is not sure what is desired when the number of names in the list is not divisible by 3.&amp;nbsp; In those cases your logic will generate LIST_OF_3 with only one or two names instead of three the last time through the outer loop since %SCAN() returns empty string with you scan past the end of the list.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 03:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836455#M330723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-03T03:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Slide a list into smaller list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836527#M330753</link>
      <description>&lt;P&gt;Thanks you all.&lt;/P&gt;
&lt;P&gt;&lt;A title="A reply to Kurt_Bremser's message from 10-02-2022" href="https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836419#M330710" target="_blank"&gt;@Kurt_Bremser&lt;/A&gt;&amp;nbsp;code work perfectly well.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2022 15:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Slide-a-list-into-smaller-list/m-p/836527#M330753</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-10-03T15:03:51Z</dc:date>
    </item>
  </channel>
</rss>

