<?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: Diagonal Frequency within Proc Freq in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591609#M15236</link>
    <description>&lt;P&gt;Please try the below code where I created the ID variable with value 'x=y' and used proc freq with subset of x eq y and in table statement id, hope it helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input x y;
id='x=y';
datalines;
18 1
9 8
18 9
12 8
6 6
19 3
15 18
9 12
20 9
2 3
7 2
1 5
3 18
12 12
12 18
5 8
3 4
12 5
2 14
19 19
12 5
12 15
12 18
17 19
9 10
8 20
5 17
8 16
16 18
3 12
18 5
12 14
16 16
6 10
13 18
13 9
17 5
3 18
10 10
;
run;

proc freq data=have;
where x eq y;
table id/out=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 Sep 2019 16:27:59 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2019-09-25T16:27:59Z</dc:date>
    <item>
      <title>Diagonal Frequency within Proc Freq</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591605#M15234</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an option or somethin &lt;U&gt;&lt;STRONG&gt;within proc freq&lt;/STRONG&gt;&lt;/U&gt; that would give me the diagonal frequency (i.e. sum of count when x=y)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, is there a method/option that can give me frequencies for counts when they are 1(or more) cell above/below the diagonal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y;
datalines;
18 1
9 8
18 9
12 8
6 6
19 3
15 18
9 12
20 9
2 3
7 2
1 5
3 18
12 12
12 18
5 8
3 4
12 5
2 14
19 19
12 5
12 15
12 18
17 19
9 10
8 20
5 17
8 16
16 18
3 12
18 5
12 14
16 16
6 10
13 18
13 9
17 5
3 18
10 10
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 16:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591605#M15234</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2019-09-25T16:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Diagonal Frequency within Proc Freq</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591607#M15235</link>
      <description>&lt;P&gt;No, but it's easy to synthesize in PROC SQL.&lt;/P&gt;
&lt;P&gt;You can then use PROC TRANSPOSE to flip your data if desired.&amp;nbsp;&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;*diagonal;
proc sql;
create table want1 as
select x, y, count(*) as N_occurences
from have
group by x, y;
quit;

*above diagonal;
proc sql;
create table want2 as
select x, y, count(*) as N_occurences
from have
where y&amp;gt;x
group by x, y;
quit;

* diagonal + above diagonal;
proc sql;
create table want3 as
select x, y, count(*) as N_occurences
from have
where y&amp;gt;=x
group by x, y;
quit;&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 you then want it in a matrix type structure use PROC TRANSPOSE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215179"&gt;@david27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the below dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there an option or somethin &lt;U&gt;&lt;STRONG&gt;within proc freq&lt;/STRONG&gt;&lt;/U&gt; that would give me the diagonal frequency (i.e. sum of count when x=y)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, is there a method/option that can give me frequencies for counts when they are 1(or more) cell above/below the diagonal?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y;
datalines;
18 1
9 8
18 9
12 8
6 6
19 3
15 18
9 12
20 9
2 3
7 2
1 5
3 18
12 12
12 18
5 8
3 4
12 5
2 14
19 19
12 5
12 15
12 18
17 19
9 10
8 20
5 17
8 16
16 18
3 12
18 5
12 14
16 16
6 10
13 18
13 9
17 5
3 18
10 10
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2019 16:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591607#M15235</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-25T16:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Diagonal Frequency within Proc Freq</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591609#M15236</link>
      <description>&lt;P&gt;Please try the below code where I created the ID variable with value 'x=y' and used proc freq with subset of x eq y and in table statement id, hope it helps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input x y;
id='x=y';
datalines;
18 1
9 8
18 9
12 8
6 6
19 3
15 18
9 12
20 9
2 3
7 2
1 5
3 18
12 12
12 18
5 8
3 4
12 5
2 14
19 19
12 5
12 15
12 18
17 19
9 10
8 20
5 17
8 16
16 18
3 12
18 5
12 14
16 16
6 10
13 18
13 9
17 5
3 18
10 10
;
run;

proc freq data=have;
where x eq y;
table id/out=want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Sep 2019 16:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591609#M15236</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-09-25T16:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Diagonal Frequency within Proc Freq</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591612#M15237</link>
      <description>I stand corrected &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;For the second option, change the where to be:&lt;BR /&gt;&lt;BR /&gt;WHERE Y &amp;gt;=X before doing your proc freq. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Will provide diagonals and upper triangle. &lt;BR /&gt;proc freq data=have;&lt;BR /&gt;where Y&amp;gt;=X;&lt;BR /&gt;table X*Y;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 25 Sep 2019 16:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Diagonal-Frequency-within-Proc-Freq/m-p/591612#M15237</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-25T16:39:26Z</dc:date>
    </item>
  </channel>
</rss>

