<?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: Cross-tab frequency table based on number of  multiple responses in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797204#M81598</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input group_id survey_id;
datalines;
111 1
111 4
111 2
222 3
333 4
333 5
333 2
333 1
444 2
;

proc sql;
create table temp as
select a.survey_id as a_survey_id,b.survey_id as b_survey_id
 from (select * from have group by group_id having count(*)&amp;gt;1) as a,
      (select * from have group by group_id having count(*)&amp;gt;1) as b
  where a.group_id=b.group_id and a.survey_id&amp;gt;=b.survey_id ;

create table want as
select a_survey_id,b_survey_id,sum(count) as sum
from
(
select c.*,coalesce(d.count,0) as count
from
(
select a.survey_id as a_survey_id,b.survey_id as b_survey_id
 from (select distinct survey_id from have) as a,(select distinct survey_id from have) as b
) as c natural left join (select *,1 as count from temp) as d
)
group by a_survey_id,b_survey_id
order by b_survey_id,a_survey_id
;
quit;

proc transpose data=want out=final_want ;
by b_survey_id;
id a_survey_id;
var sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 18 Feb 2022 12:12:52 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-02-18T12:12:52Z</dc:date>
    <item>
      <title>Cross-tab frequency table based on number of  multiple responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797120#M81596</link>
      <description>&lt;P&gt;I have a data set&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=""&gt;data have;
input group_id survey_id;
datalines;
111 1
111 4&lt;BR /&gt;111 2
222 3
333 4
333 5&lt;BR /&gt;333 2
333 1
444 2
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Some group_id variables have multiple survey_id responses. I want the following table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Survey_id&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't fill the bottom half, since it'll be the same as the upper half.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Basically, the table should be only for those with multiple group_id's (so I ignore the group_id 222 and 444).&amp;nbsp; Then, it counts the number of group_id's in each cell (e.g. the cell with Survey_id = 1x4 counts the number of group_id (where there are duplicates of the group_id's) that have both survey_id = 1 and 4).&amp;nbsp;&amp;nbsp;&lt;BR /&gt;Can someone show me how to do this easily? Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 01:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797120#M81596</guid>
      <dc:creator>yellowyellowred</dc:creator>
      <dc:date>2022-02-18T01:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-tab frequency table based on number of  multiple responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797180#M81597</link>
      <description>&lt;P&gt;Now describe just how any of those cells in the "want" are derived.&lt;/P&gt;
&lt;P&gt;Computer code uses rules and we need to know the rules. Examples help but the rules are needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I provide the following example:&lt;/P&gt;
&lt;P&gt;Input Output&lt;/P&gt;
&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;can you tell me what the result for 13 or 444 much less infinity would be? (8 and 23 )&lt;/P&gt;
&lt;P&gt;Much less infinity?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 09:33:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797180#M81597</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-18T09:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-tab frequency table based on number of  multiple responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797204#M81598</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input group_id survey_id;
datalines;
111 1
111 4
111 2
222 3
333 4
333 5
333 2
333 1
444 2
;

proc sql;
create table temp as
select a.survey_id as a_survey_id,b.survey_id as b_survey_id
 from (select * from have group by group_id having count(*)&amp;gt;1) as a,
      (select * from have group by group_id having count(*)&amp;gt;1) as b
  where a.group_id=b.group_id and a.survey_id&amp;gt;=b.survey_id ;

create table want as
select a_survey_id,b_survey_id,sum(count) as sum
from
(
select c.*,coalesce(d.count,0) as count
from
(
select a.survey_id as a_survey_id,b.survey_id as b_survey_id
 from (select distinct survey_id from have) as a,(select distinct survey_id from have) as b
) as c natural left join (select *,1 as count from temp) as d
)
group by a_survey_id,b_survey_id
order by b_survey_id,a_survey_id
;
quit;

proc transpose data=want out=final_want ;
by b_survey_id;
id a_survey_id;
var sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Feb 2022 12:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/797204#M81598</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-18T12:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-tab frequency table based on number of  multiple responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/798265#M81613</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks. It works perfectly. I was wondering what the difference betwen a natural left join and a left join is? I searched online but can't figure it out.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 22:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/798265#M81613</guid>
      <dc:creator>yellowyellowred</dc:creator>
      <dc:date>2022-02-23T22:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cross-tab frequency table based on number of  multiple responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/798363#M81617</link>
      <description>They are the same. NATURAL will automatically find the same variables between left and right table and use these variables in common as  the KEY variables to JOIN . NATURAL could save you some words , &lt;BR /&gt;it is the same as " LEFT JOIN ON  a.a_survey_id=b.a_survey_id  and  a.b_survey_id=b.b_survey_id "</description>
      <pubDate>Thu, 24 Feb 2022 11:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Cross-tab-frequency-table-based-on-number-of-multiple-responses/m-p/798363#M81617</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-02-24T11:52:14Z</dc:date>
    </item>
  </channel>
</rss>

