<?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: sum a large number of variable pairs: PLEASE HELP :) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838295#M331435</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data long_sum;
	set have;
	array v(60); *list of variables with diseases;

	do index1=1 to dim(v);

		do index2=index1+1 to dim(v);
		    if v(index1)=1 and v(index2)=1 then do;
			disease1 = vname(v(index1)); *gets disease name;
			disease2 = vname(v(index2));
			output;
		end;
	end;
	end;
	drop v:;
run;

proc freq data=long_sum order=freq;
table disease1*disease2 / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74483"&gt;@hein68&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The variables are all binary, with values of 0 or 1. Numeric variables.&lt;BR /&gt;&lt;BR /&gt;Each variable is for a different medical diagnosis category. 1=Yes (patient has that disease) 0=No (patient does not have that disease)&lt;BR /&gt;&lt;BR /&gt;I need to find the most common disease pairings that co-occur in patients.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Oct 2022 20:13:44 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-10-12T20:13:44Z</dc:date>
    <item>
      <title>sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838290#M331430</link>
      <description>&lt;P&gt;Hello.&amp;nbsp; I have a tricky programming issue that I need help with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 60 variables.&amp;nbsp; For simplicity, let's say they are called v1, v2, v3, .... v60.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to sum all of the possible pairs of these variables.&amp;nbsp; In other words, I need a sum of v1v2, v1v3, v1v4, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I will run frequencies to see which combinations are the most common.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also need to do something similar for combinations of 3 within the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 19:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838290#M331430</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-12T19:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838291#M331431</link>
      <description>&lt;P&gt;What do you mean by&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I need to sum all of the possible pairs of these variables.&amp;nbsp; In other words, I need a sum of v1v2, v1v3, v1v4, etc.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How can you sum v1v2 if v1v2 is not a variable? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or is it a variable that has to be created? If so, how is it created?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 19:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838291#M331431</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-12T19:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838292#M331432</link>
      <description>Something like this would work for me:&lt;BR /&gt;&lt;BR /&gt;V1V2=sum(of v1, v2);&lt;BR /&gt;&lt;BR /&gt;Or something like this:&lt;BR /&gt;&lt;BR /&gt;If v1=1 and v2=1 then v1v2=1;&lt;BR /&gt;&lt;BR /&gt;I need to find all the cases where v1 and v2 both equal 1.  That’s easy enough.  But I need to do that for all possible combinations of the 60 variables (v1, v2, v3, … v60).&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Oct 2022 19:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838292#M331432</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-12T19:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838293#M331433</link>
      <description>&lt;P&gt;What type of values are in V1-V60? Are they all binary for example? Can you explain the problem you're trying to solve here, there may be other ways that are more efficient. You mention 60 variables, what about the rows of each of those variables? You have multiple rows or a single row. It may be best to show a fully worked example for say 5 'variables'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Modifying the example as you say your variables are likely Bernoulli.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*make fake data to work with;
data have;
	call streaminit(30);
	array v(60);

	do record=1 to 100;

		do i=1 to 60;
				v(i)=rand('bernoulli', 0.7);			
		end;
		output;
	end;
	drop i;
run;

*sum and flip long;
data long_sum;
	set have;
	array v(60);

	do index1=1 to dim(v);

		do index2=index1+1 to dim(v);
			sum=Sum(v(index1), v(index2));
			output;
		end;
	end;
	drop v:;
run;

*sort descending to get most frequent at the top;
proc sort data=long_sum;
	by descending sum index1 index2;
run;

proc print data=long_sum (obs=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74483"&gt;@hein68&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello.&amp;nbsp; I have a tricky programming issue that I need help with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 60 variables.&amp;nbsp; For simplicity, let's say they are called v1, v2, v3, .... v60.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to sum all of the possible pairs of these variables.&amp;nbsp; In other words, I need a sum of v1v2, v1v3, v1v4, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I will run frequencies to see which combinations are the most common.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also need to do something similar for combinations of 3 within the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 20:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838293#M331433</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-12T20:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838294#M331434</link>
      <description>The variables are all binary, with values of 0 or 1.  Numeric variables.&lt;BR /&gt;&lt;BR /&gt;Each variable is for a different medical diagnosis category.  1=Yes (patient has that disease) 0=No (patient does not have that disease)&lt;BR /&gt;&lt;BR /&gt;I need to find the most common disease pairings that co-occur in patients.&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Oct 2022 20:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838294#M331434</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-12T20:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838295#M331435</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data long_sum;
	set have;
	array v(60); *list of variables with diseases;

	do index1=1 to dim(v);

		do index2=index1+1 to dim(v);
		    if v(index1)=1 and v(index2)=1 then do;
			disease1 = vname(v(index1)); *gets disease name;
			disease2 = vname(v(index2));
			output;
		end;
	end;
	end;
	drop v:;
run;

proc freq data=long_sum order=freq;
table disease1*disease2 / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74483"&gt;@hein68&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The variables are all binary, with values of 0 or 1. Numeric variables.&lt;BR /&gt;&lt;BR /&gt;Each variable is for a different medical diagnosis category. 1=Yes (patient has that disease) 0=No (patient does not have that disease)&lt;BR /&gt;&lt;BR /&gt;I need to find the most common disease pairings that co-occur in patients.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 20:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838295#M331435</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-12T20:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838296#M331436</link>
      <description>&lt;P&gt;The variables are all binary, with values of 0 or 1.&amp;nbsp; Numeric variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each variable is for a different medical diagnosis category.&amp;nbsp; 1=Yes (patient has that disease), 0=No (patient does not have that disease)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to find the most common disease pairings that co-occur in patients.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is code that I wrote for 5 variables (see below), but I need to do this for all possible pairings of 60 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if v1=1 and v2=1 then v1v2=1;&lt;BR /&gt;if v1=1 and v3=1 then v1v3=1;&lt;BR /&gt;if v1=1 and v4=1 then v1v4=1;&lt;BR /&gt;if v1=1 and v5=1 then v1v5=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if v2=1 and v3=1 then v1v3=1;&lt;BR /&gt;if v2=1 and v4=1 then v1v4=1;&lt;BR /&gt;if v2=1 and v5=1 then v1v5=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if v3=1 and v4=1 then v1v4=1;&lt;BR /&gt;if v3=1 and v5=1 then v1v5=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if v4=1 and v5=1 then v1v5=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 20:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838296#M331436</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-12T20:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838299#M331439</link>
      <description>&lt;P&gt;Code isn't helpful, example input data and expected output is more helpful. Regardless, I think the solution I've provided will work for your use case.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 20:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838299#M331439</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-12T20:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838301#M331440</link>
      <description>Good approach, but note that the outer loop should stop at dim(v)-1 not dim(v).</description>
      <pubDate>Wed, 12 Oct 2022 20:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838301#M331440</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-10-12T20:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838306#M331443</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long_sum;
	set have;
	array v(60); *list of variables with diseases;

	do index1=1 to dim(v)-1;

		do index2=index1+1 to dim(v);
		    if v(index1)=1 and v(index2)=1 then do;
			disease1 = vname(v(index1)); *gets disease name;
			disease2 = vname(v(index2));
			output;
		end;
	end;
	end;
	drop v:;
run;

proc freq data=long_sum order=freq;
table disease1*disease2 / list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 21:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838306#M331443</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-12T21:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838307#M331444</link>
      <description>&lt;P&gt;Ok, I think that's reasonably clear now. But please answer this ... why are you doing this? What analysis or report will come next. Please don't ignore this question, because I really think you have decided on a solution that is not optimal, when there might be much better solutions out there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is always a red flag for me —someone decides they need to do something difficult and unusual, and so that's the discussion; but the discussion really should be about the analysis or report you need to do first, and then provide code that gets you there. This is the &lt;A href="https://en.wikipedia.org/wiki/XY_problem" target="_self"&gt;XY Problem&lt;/A&gt;, textbook example.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 21:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838307#M331444</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-12T21:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838309#M331445</link>
      <description>&lt;P&gt;This worked for me, thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 21:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838309#M331445</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-12T21:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838310#M331446</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 21:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838310#M331446</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-12T21:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838369#M331476</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*It is a matrix cross product .*/
data have;
 call streaminit(30);
 array v(60);

 do record=1 to 100;

  do i=1 to 60;
    v(i)=rand('bernoulli', 0.7);   
  end;
  output;
 end;
 drop i;
run;

proc corr data=have sscp out=want(drop=intercept where=(_type_='SSCP' and _name_ ne 'Intercept')) noprint;
var v1-v60;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Oct 2022 11:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838369#M331476</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-13T11:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: sum a large number of variable pairs: PLEASE HELP :)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838436#M331505</link>
      <description>Thanks!&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Oct 2022 16:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-a-large-number-of-variable-pairs-PLEASE-HELP/m-p/838436#M331505</guid>
      <dc:creator>hein68</dc:creator>
      <dc:date>2022-10-13T16:30:46Z</dc:date>
    </item>
  </channel>
</rss>

