<?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: Creating a 2x2 table with variables from multiple tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850470#M336115</link>
    <description>&lt;P&gt;We would need to see the data in these multiple tables in order to provide code. Please provide (a portion of) the data as working SAS data step code, which you can type in yourself, or use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Make sure the code is working. Do not provide data as screen captures or as file attachments.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Dec 2022 13:03:18 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-12-20T13:03:18Z</dc:date>
    <item>
      <title>Creating a 2x2 table with variables from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850458#M336112</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am fairly new to SAS and I'm grateful for any input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a 2x2 table in which the number of rows are retrieved from multiple variables in multiple tables in order to calculate sensitivity and specificity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically, I want to retreive the number of rows in three different columns in three different tables. The three counts reflect the number of records in database 1, database 2 and number of matches between the two databases.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally, I'd like SAS to calculate the missing values and end up with a table like this one:&amp;nbsp;&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;&lt;STRONG&gt;Database 2&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Yes&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;No&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Total&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;EM&gt;Database 1&lt;/EM&gt;&lt;/STRONG&gt;&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;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;EM&gt;Yes&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;700&lt;/TD&gt;&lt;TD&gt;to be calculated&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;800&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;EM&gt;No&lt;/EM&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;to be calculated&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;to be calculated&lt;/TD&gt;&lt;TD&gt;to be calculated&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;TD&gt;920&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However I am already stuck at retrieving the counts. I have tried with the following insert into statement (table3 has already been created) but it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
	insert into table3 (count1, count2, match)
		select count (ID1) from table1,
		select count (ID2) from table2,
		select count (match) from table3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 09:22:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850458#M336112</guid>
      <dc:creator>ha33</dc:creator>
      <dc:date>2022-12-20T09:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a 2x2 table with variables from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850470#M336115</link>
      <description>&lt;P&gt;We would need to see the data in these multiple tables in order to provide code. Please provide (a portion of) the data as working SAS data step code, which you can type in yourself, or use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Make sure the code is working. Do not provide data as screen captures or as file attachments.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 13:03:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850470#M336115</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-20T13:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a 2x2 table with variables from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850471#M336116</link>
      <description>&lt;P&gt;Not really sure what the output table you show is designed to represent, but I can help you get the statistics. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
   do ID1=1 to 100 by 2;
		output;
	end;
run;
data two;
   do ID2=1 to 100 by 3;
		output;
	end;
run;

proc sql;
title 'Input Table Row Counts';
select 'One' as Table, count(*) as Count from One
  union all
select 'Two',count(*) from Two
;
title 'Table Comparison Counts';
select 
       sum (id1 and id2) as Match
		,sum (sum(missing(id1),missing(id2))) as NoMatch
		,count(ID1) as Rows1 'Rows in One'
		,count(ID2) as Rows2 'Rows in Two'
		,count(*)   as JoinRows 'Full Join Rows'
		,sum(count(ID1),count(ID2)) as Total 'All Rows'
	from one
		full join 
		  two
	on one.id1=two.id2
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Produces this result:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Input Table Row Counts&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;Table&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Count&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;One&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Two&lt;/TD&gt;
&lt;TD class="r data"&gt;34&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="branch"&gt;&lt;STRONG&gt;Table Comparison Counts&lt;/STRONG&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;Match&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;NoMatch&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Rows in One&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Rows in Two&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;Full Join Rows&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;All Rows&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;17&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;TD class="r data"&gt;50&lt;/TD&gt;
&lt;TD class="r data"&gt;34&lt;/TD&gt;
&lt;TD class="r data"&gt;67&lt;/TD&gt;
&lt;TD class="r data"&gt;84&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 13:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850471#M336116</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-12-20T13:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a 2x2 table with variables from multiple tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850476#M336119</link>
      <description>&lt;P&gt;If that is supposed to a simple cross tab (Think PROC FREQ with two variables) then you are missing on piece of information to complete the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 192pt;" border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.4pt; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;YES&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;NO&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;YES&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;B-A&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;NO&lt;/TD&gt;
&lt;TD&gt;C-A&lt;/TD&gt;
&lt;TD&gt;x&lt;/TD&gt;
&lt;TD&gt;C-A+x&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;C&lt;/TD&gt;
&lt;TD&gt;B-A+x&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have given values for A, B and C which will allow you fill in two of the empty cells.&amp;nbsp; But you can then pick any value for X and generate values for the other three cells.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With A=700 and B=800 and C=920 if we set X = 100 then the table will be:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 192pt;" border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD width="64" height="19" style="height: 14.4pt; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;YES&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;NO&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;YES&lt;/TD&gt;
&lt;TD&gt;700&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;800&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;NO&lt;/TD&gt;
&lt;TD&gt;220&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;320&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.4pt;"&gt;
&lt;TD height="19" style="height: 14.4pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;920&lt;/TD&gt;
&lt;TD&gt;200&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know the overall N?&amp;nbsp; If so then you do have enough information since C+B-A+x=N&amp;nbsp; which means that X is N-C-B+A.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Dec 2022 13:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-2x2-table-with-variables-from-multiple-tables/m-p/850476#M336119</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-12-20T13:59:57Z</dc:date>
    </item>
  </channel>
</rss>

