<?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 Create proc freq crosstab for all column combinations in a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918094#M361654</link>
    <description>&lt;P&gt;Hi fellow SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create 2x2 tables with Cramer's V to assess correlation of categorical variables. It is a very large table with many columns, but for this example, lets say:&lt;/P&gt;&lt;P&gt;I have a table consisting of 5 columns called A, B, C, D, and E. I want to output a proc freq with Cramer's V for each combination. I know I can do something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data=dataset; table (A--E)*(A--E) / chisq; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I don't want duplicates (i.e., I do not need both the A*B and B*A crosstabs). I do not have much experience writing arrays, but I think it should be possible to accomplish this task using one. The real table has 30+ columns, so typing out all the combinations to avoid duplications isn't practical.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help the community can provide!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Feb 2024 18:12:31 GMT</pubDate>
    <dc:creator>irvinery</dc:creator>
    <dc:date>2024-02-27T18:12:31Z</dc:date>
    <item>
      <title>Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918094#M361654</link>
      <description>&lt;P&gt;Hi fellow SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create 2x2 tables with Cramer's V to assess correlation of categorical variables. It is a very large table with many columns, but for this example, lets say:&lt;/P&gt;&lt;P&gt;I have a table consisting of 5 columns called A, B, C, D, and E. I want to output a proc freq with Cramer's V for each combination. I know I can do something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data=dataset; table (A--E)*(A--E) / chisq; run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I don't want duplicates (i.e., I do not need both the A*B and B*A crosstabs). I do not have much experience writing arrays, but I think it should be possible to accomplish this task using one. The real table has 30+ columns, so typing out all the combinations to avoid duplications isn't practical.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help the community can provide!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 18:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918094#M361654</guid>
      <dc:creator>irvinery</dc:creator>
      <dc:date>2024-02-27T18:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918098#M361655</link>
      <description>&lt;P&gt;I would re-arrange the data such that you can use a BY statement in PROC FREQ. (Alternative is to use a macro)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input a b c d e;
    cards;
7 10 11 12 14
7 11 10 12 13
8 10 12 13 14
;

data re_arrange;
    set have;
    array v a--e;
    do i=1 to dim(v)-1;
        do j=i+1 to dim(v);
            value1=v(i);
            value2=v(j);
            type = cats(vname(v(i)),'*',vname(v(j)));
            output;
        end;
    end;
    drop i j;
run;
proc sort data=re_arrange;
    by type;
run;

proc freq data=re_arrange;
    by type;
    table value1*value2/chisq;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sending this to a text or html output would produce a very long report where you need just a tiny fraction of the results to get Cramer's V. Better would be sending the statistics to a data set, called CHISQ and then filtering the row so you get only the cases where STATISTIC="Cramer's V". Replace the PROC FREQ with this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
ods output chisq=chisq(where=(statistic=:'Cram') drop=table);
proc freq data=re_arrange;
    by type;
    table value1*value2/chisq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If all the variables have labels (which I would strongly recommend), you could then use the VLABEL() function instread of the VNAME() function.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 18:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918098#M361655</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-27T18:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918103#M361660</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413154"&gt;@irvinery&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi fellow SAS users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create 2x2 tables with Cramer's V to assess correlation of categorical variables. It is a very large table with many columns, but for this example, lets say:&lt;/P&gt;
&lt;P&gt;I have a table consisting of 5 columns called A, B, C, D, and E. I want to output a proc freq with Cramer's V for each combination. I know I can do something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;proc freq data=dataset; table (A--E)*(A--E) / chisq; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I don't want duplicates (i.e., I do not need both the A*B and B*A crosstabs). I do not have much experience writing arrays, but I think it should be possible to accomplish this task using one. The real table has 30+ columns, so typing out all the combinations to avoid duplications isn't practical.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance for any help the community can provide!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since Arrays only exist for the duration of a data step or Proc Iml I am not sure how you are thinking of using this.&lt;/P&gt;
&lt;P&gt;Unless you are thinking of placing the the names of the variables into an array and using one of the combinatorial functions to write the code.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 18:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918103#M361660</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-27T18:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918104#M361661</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413154"&gt;@irvinery&lt;/a&gt;&amp;nbsp;it seems to me it is wrong to mark that as the correct answer, as I have already shown how to use arrays in this problem.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 19:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918104#M361661</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-27T19:09:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918107#M361662</link>
      <description>Hi Paige,&lt;BR /&gt;I didn't select that as the right answer, so I"m not sure how that happened.</description>
      <pubDate>Tue, 27 Feb 2024 19:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918107#M361662</guid>
      <dc:creator>irvinery</dc:creator>
      <dc:date>2024-02-27T19:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918109#M361663</link>
      <description>&lt;P&gt;You can change the selection easily:&amp;nbsp;Select a different post&amp;nbsp;as the solution after clicking&amp;nbsp;"Not the Solution" in the option menu (see icon below) of the current solution.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="show_option_menu.png" style="width: 155px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94172i5C1D3601EF1BF927/image-size/large?v=v2&amp;amp;px=999" role="button" title="show_option_menu.png" alt="show_option_menu.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 19:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918109#M361663</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-02-27T19:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Create proc freq crosstab for all column combinations in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918844#M361934</link>
      <description>Done! Thanks again for the help.</description>
      <pubDate>Mon, 04 Mar 2024 15:35:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-proc-freq-crosstab-for-all-column-combinations-in-a/m-p/918844#M361934</guid>
      <dc:creator>irvinery</dc:creator>
      <dc:date>2024-03-04T15:35:14Z</dc:date>
    </item>
  </channel>
</rss>

