<?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 Help with Do loop through a list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248530#M268676</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;My data has a list of variable say a b c d e.&lt;/P&gt;
&lt;P&gt;I want to create a Do Loop through a combination of this list.&lt;/P&gt;
&lt;P&gt;My maincode working with manual combination such as:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let var1=a; &amp;nbsp;%let var2=b;&lt;/P&gt;
&lt;P&gt;*main code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I do something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let List_variable = a b &amp;nbsp;c d e;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 to the end of the list_variable;&lt;/P&gt;
&lt;P&gt;%do j=i+1 to the end of the list_variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dont know how to turn count (i) into name of variable a,bcde..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&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 target a b c d e;
cards;
1 1 2 3 0 6
2 1 2 0 0 6
-1 1 2 0 8 16
-2 2 0 0 8 16
5 0 0 0 8 31
6 0 0 2 2 31
1 1 2 0 1 2
run;

%let var1=a;
%let var2=b;

proc reg data=have ;
   model &amp;amp;var1 = &amp;amp;var2 ;
run;

%let var1=a;
%let var2=c;

proc reg data=have ;
   model &amp;amp;var1 = &amp;amp;var2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Feb 2016 05:22:32 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2016-02-07T05:22:32Z</dc:date>
    <item>
      <title>Help with Do loop through a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248530#M268676</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;My data has a list of variable say a b c d e.&lt;/P&gt;
&lt;P&gt;I want to create a Do Loop through a combination of this list.&lt;/P&gt;
&lt;P&gt;My maincode working with manual combination such as:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let var1=a; &amp;nbsp;%let var2=b;&lt;/P&gt;
&lt;P&gt;*main code;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I do something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let List_variable = a b &amp;nbsp;c d e;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%do i=1 to the end of the list_variable;&lt;/P&gt;
&lt;P&gt;%do j=i+1 to the end of the list_variable;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I dont know how to turn count (i) into name of variable a,bcde..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&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 target a b c d e;
cards;
1 1 2 3 0 6
2 1 2 0 0 6
-1 1 2 0 8 16
-2 2 0 0 8 16
5 0 0 0 8 31
6 0 0 2 2 31
1 1 2 0 1 2
run;

%let var1=a;
%let var2=b;

proc reg data=have ;
   model &amp;amp;var1 = &amp;amp;var2 ;
run;

%let var1=a;
%let var2=c;

proc reg data=have ;
   model &amp;amp;var1 = &amp;amp;var2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2016 05:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248530#M268676</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-07T05:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Do loop through a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248533#M268677</link>
      <description>&lt;P&gt;You can use %scan to find the i'th element in the list. You should probably look into Call ALLCOMB though, it's probably an easier way to generate all your 2/3 options and more scalable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=a b c d e;

%macro loop(vlist);
%let nwords=%sysfunc(countw(&amp;amp;vlist));

%do i=1 %to &amp;amp;nwords;
%do j=&amp;amp;i+1 %to &amp;amp;nwords;

%put %scan(&amp;amp;vlist, &amp;amp;i) + %scan(&amp;amp;vlist, &amp;amp;j);

%end;
%end;
%mend;

%loop(&amp;amp;list);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Feb 2016 06:08:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248533#M268677</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-07T06:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Do loop through a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248654#M268678</link>
      <description>&lt;P&gt;That works perfectly.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Mon, 08 Feb 2016 13:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Do-loop-through-a-list-of-variables/m-p/248654#M268678</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-08T13:28:58Z</dc:date>
    </item>
  </channel>
</rss>

