<?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 through a unknow number of value i and variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248494#M268662</link>
    <description>&lt;P&gt;Sounds a bit like market basket analysis. Have you tried any of the&amp;nbsp;MBA macros?&lt;/P&gt;</description>
    <pubDate>Sat, 06 Feb 2016 19:04:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-02-06T19:04:05Z</dc:date>
    <item>
      <title>Do Loop through a unknow number of value i and variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248487#M268661</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data with a Target variable and a number of condition variable ( a b c d e f).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each combination of 2 condition value (a=1, b=2 OR a=1, b=1...). I want to count the number of record for each Target Value &lt;BR /&gt;under CERTAIN condition. (I will extend it to 3 conditions in the future)&lt;/P&gt;
&lt;P&gt;Because of the conditions I will impose to process each subsample, I need to &lt;BR /&gt;structure the code as below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think my issue is to get SAS automatically know the number of discrete value for each variable and let it run through them;&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;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 2 0 0 8 31
6 0 1 2 2 31
run;



*pull record for a given condition ---&lt;BR /&gt;*this one later will be built in a Do loop &amp;amp;var1=a &amp;amp;va1_value=1 &amp;amp;var2=b var2_value=2;
data temp1; set have;	
if a=1 and b=2; 
run;&lt;BR /&gt;
*section to add condtion to process the data;
*section to add condtion to process the data;
&lt;BR /&gt;*summary the number of record-------------------------------------------;
proc freq data=temp1;
table target/out=temp2 (drop = PERCENT);run;
&lt;BR /&gt;*standardizethe report so it can be added to a master file--------------;
proc transpose data=temp2 out=temp3 (drop =_LABEL_) prefix=target_value;
id target;
run;

data report; set temp3;
var1="a";
var1_value=1;
var2="b";
var2_value=2;run;

*So at that step, I am done with the first combination of 2 factors;
*I need a do loop to go over all variable and all value available for each factor;

*I think 1 issue is to get SAS automatically know the number of  discrete value for each variable &lt;BR /&gt;and let it run through them;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2016 17:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248487#M268661</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-06T17:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop through a unknow number of value i and variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248494#M268662</link>
      <description>&lt;P&gt;Sounds a bit like market basket analysis. Have you tried any of the&amp;nbsp;MBA macros?&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2016 19:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248494#M268662</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-06T19:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop through a unknow number of value i and variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248501#M268663</link>
      <description>&lt;P&gt;After thinking more about it, I think the following framework below could potentially ok.&lt;/P&gt;
&lt;P&gt;But how I can get SAS know the list of dicrete value for each variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I am not familiar with&amp;nbsp;&lt;SPAN&gt;MBA macros)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let VARIABLE_NAME= A B C D E;
%let variable_value
do i=1 to dim(VARIABLE_NAME);
  do j=i+1 to dim(VARIABLE_NAME);	* 
  	do k=1 to dim(variable_value);
		do l=1 to dim(variable_value)

		data temp; set have;  *Get the data needed;
		if VARIABLE_NAME(i)=variable_value(k) and VARIABLE_NAME(j)=variable_value(l);
		run;

		*** run the middle code***;
end;
end;	
end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2016 19:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248501#M268663</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-06T19:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop through a unknow number of value i and variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248502#M268664</link>
      <description>&lt;P&gt;Your mixing SAS base code and macro code...you'll need macro variables instead and %do loops. You can get the numbers by running a proc freq on your dataset and creating macro variables from the results.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2016 19:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248502#M268664</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-06T19:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop through a unknow number of value i and variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248505#M268665</link>
      <description>&lt;P&gt;So the code below will generate the distint value for each variables.&lt;/P&gt;
&lt;P&gt;I am not sure how to take information from this table to work with the original table.&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 2 0 0 8 31
6 0 1 2 2 31
run;

proc summary data=have missing chartype; 
   class _all_;
   ways 1; 
   output out=distinct(drop=_type_ _freq_) / levels; 
   run; 

proc sort data=distinct;
   by _level_;
   run; 
data Variable_value;
   update distinct(obs=0) distinct;
   by _level_;
   run; 
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Feb 2016 20:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-through-a-unknow-number-of-value-i-and-variable-name/m-p/248505#M268665</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2016-02-06T20:13:22Z</dc:date>
    </item>
  </channel>
</rss>

