<?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: Help me with summary on combination of variables' value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109330#M292121</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc summary or SQL group by...?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select a1, a2, target, count(*) as nobs&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by a1, a2, target;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Aug 2013 13:38:13 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2013-08-13T13:38:13Z</dc:date>
    <item>
      <title>Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109329#M292120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset that have a Target Variable and a number of independent variables, say a1 a2 … a6 as below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create a summary file of the target value for each combination of independent variable and their value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically the summary will answer the question:&lt;/P&gt;&lt;P&gt;If a1=5 and a2=9,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; how many observations have target=0 and how many have target=1.&lt;/P&gt;&lt;P&gt;If a1=4 and a2=1,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; how many observations have target=0 and how many have target=1.&lt;/P&gt;&lt;P&gt;…&lt;/P&gt;&lt;P&gt;If a1=5 and a3=1,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; how many observations have target=0 and how many have target=1.&lt;/P&gt;&lt;P&gt;…..&lt;/P&gt;&lt;P&gt;I really appreciate it if you could help me with this problem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt; background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;data have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; input target a1 a2 a3 a4 a5 a6;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; datalines;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;0 5 9 1 0 8 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;1 4 0 1 1 5 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;1 8 1 2 3 1 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;1 3 3 0 2 0 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;0 4 1 1 7 0 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;0 3 3 0 9 0 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;1 2 1 1 2 1 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;0 1 2 0 3 0 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background-color: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 13:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109329#M292120</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-08-13T13:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109330#M292121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc summary or SQL group by...?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select a1, a2, target, count(*) as nobs&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by a1, a2, target;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 13:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109330#M292121</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-08-13T13:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109331#M292122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your answer.&lt;/P&gt;&lt;P&gt;My problem is that I want SAS to create the summary across ALL combination of variable and ALL value.&lt;/P&gt;&lt;P&gt;I should have clarify it in the original post.&lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 13:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109331#M292122</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-08-13T13:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109332#M292123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So what combinations do wish to calculate? I can't see the pattern in your example...?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 14:02:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109332#M292123</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-08-13T14:02:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109333#M292124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The easiest, soundest way would be to use PROC FREQ:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; tables a1 * a2 * a3 * a4 * a5 * a6 * target / noprint out=want (drop=percent);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will need enough memory to track all the combinations, and you will get a separate observation for each value of TARGET.&amp;nbsp; It you are sure that TARGET always takes on values of 0 and 1, you could shrink the size of your data set by switching to PROC SUMMARY.&amp;nbsp; In that case, one variable would show the total number of observations, and a second variable would contain the sum of all TARGET values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc summary data=have nway;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; class a1 a2 a3 a4 a5 a6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; var target;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=want (drop=_type_) sum=target_total;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If any of the CLASS variables could contain a missing value, you would have to add the MISSING option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 14:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109333#M292124</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-08-13T14:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109334#M292125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, there are 2 levels of combinations: :smileyinfo: combination of variables and (ii) combination of value of variable.&lt;/P&gt;&lt;P&gt;For the first level, I want all combination of a1-a6, which are: &lt;/P&gt;&lt;P&gt;a1a2, a1a3,a1a4,a1a5,a1a6; &lt;/P&gt;&lt;P&gt;a2a3,a2a4,a2a5,a2a5;&lt;/P&gt;&lt;P&gt;a3a4,a3a5,a3a6;&lt;/P&gt;&lt;P&gt;a4a5,a4a6;&lt;/P&gt;&lt;P&gt;and a5a6.&lt;/P&gt;&lt;P&gt;For each of the above variable-combination I want value combination. Take the first pair a1a2 as a example: &lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;a1 has value 1 2 3 4 5 8&lt;/P&gt;&lt;P style="text-indent: .5in;"&gt;a2 has value 1 2 3 9&lt;/P&gt;&lt;P&gt;I want to report how many observation with target=1 and target=0 for each value-combination as below:&lt;/P&gt;&lt;P&gt; a1=1 and a2=1: 0 observation with target=0 ; 0 observation with target=1 (In fact, for simplicity this report can be ignored since there is no such combination in the data)&lt;/P&gt;&lt;P&gt;a1=1 and a2=2:&amp;nbsp; 1 observation with target=0; 0 observation with target=1&lt;/P&gt;&lt;P&gt;….&lt;/P&gt;&lt;P&gt;a1=8 and a2=9: …&lt;/P&gt;&lt;P&gt;So I want a FULL combination of both levels (variables and value). &lt;/P&gt;&lt;P&gt;HHC&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 14:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109334#M292125</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-08-13T14:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109335#M292126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It sounds like you need the PROC SUMMARY approach, with this additional statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ways 2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess if you add WAYS 2, then NWAYS should be removed.&lt;/P&gt;&lt;P&gt;That should do it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 14:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109335#M292126</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-08-13T14:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help me with summary on combination of variables' value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109336#M292127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;I think I got it now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have; by target;run;&lt;/P&gt;&lt;P&gt;proc summary data=have;&lt;/P&gt;&lt;P&gt;by target;&lt;/P&gt;&lt;P&gt;class a1 a2 a3 a4 a5 a6;&lt;/P&gt;&lt;P&gt;ways 2;&lt;/P&gt;&lt;P&gt;output out=want (drop=_TYPE_);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*this step will help you to put all name in a field. you can feel free to delete a1-a6*/&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set want;&lt;/P&gt;&lt;P&gt;length name1 name2 $5;&lt;/P&gt;&lt;P&gt;array _a{*} a:;&lt;/P&gt;&lt;P&gt;count=0;&lt;/P&gt;&lt;P&gt;do i=1 to dim(_a);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _a{i}^=. then do; count=count+1; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if count=1 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; name1=vname(_a{i});&lt;/P&gt;&lt;P&gt;&amp;nbsp; value1=_a{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if count=2 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp; name2=vname(_a{i});&lt;/P&gt;&lt;P&gt;&amp;nbsp; value2=_a{i};&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Aug 2013 15:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-with-summary-on-combination-of-variables-value/m-p/109336#M292127</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2013-08-13T15:08:12Z</dc:date>
    </item>
  </channel>
</rss>

