<?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 Creating a new table with unique counts and percentage of an old table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352745#M82256</link>
    <description>&lt;P&gt;Hello, I have a dataset that contains 4 variables. "ID" is a unique identifier of a person in my dataset. "Location Type" is a type of location that the person is in, and only ranges from 1 to 3. "Screen" is if they were ever medically screened. "Status" has 3 entries, positive, negative, or blank. It is blank when the patient has not been screened. Here is the sample dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JANFEB.SAMPLEUNIQUE;
  infile datalines dsd truncover;
  input ID:BEST. LocationType:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,Yes,Positive
2,2,No,
3,3,Yes,Negative
4,1,No,
5,2,Yes,Positive
6,3,No,
7,1,Yes,Negative
8,2,No,
9,3,Yes,Positive
10,1,No,
11,1,Yes,Negative
12,2,Yes,Positive
13,3,Yes,Negative
14,1,No,
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I create a table from this dataset that groups screening and status results in this following way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Location Type&lt;/TD&gt;&lt;TD&gt;Screened&lt;/TD&gt;&lt;TD&gt;Positive&lt;/TD&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;TD&gt;Screening Rate&lt;/TD&gt;&lt;TD&gt;Positive Prevalence&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;30%&lt;/TD&gt;&lt;TD&gt;7%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20%&lt;/TD&gt;&lt;TD&gt;8%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50%&lt;/TD&gt;&lt;TD&gt;10%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the explanation of the columns:&lt;/P&gt;&lt;P&gt;- Screened: Unique count under each location type where the screened variable had 'Yes' in it.&lt;/P&gt;&lt;P&gt;- Positive: Unique count under each location type where the status variable had 'Positive' in it.&lt;/P&gt;&lt;P&gt;- Total: Unique count under each location type in the dataset.&lt;/P&gt;&lt;P&gt;- Screening rate: Screened/Total&lt;/P&gt;&lt;P&gt;- Positive prevalence; Positive/Screen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help!&lt;/P&gt;</description>
    <pubDate>Mon, 24 Apr 2017 08:10:30 GMT</pubDate>
    <dc:creator>byeh2017</dc:creator>
    <dc:date>2017-04-24T08:10:30Z</dc:date>
    <item>
      <title>Creating a new table with unique counts and percentage of an old table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352745#M82256</link>
      <description>&lt;P&gt;Hello, I have a dataset that contains 4 variables. "ID" is a unique identifier of a person in my dataset. "Location Type" is a type of location that the person is in, and only ranges from 1 to 3. "Screen" is if they were ever medically screened. "Status" has 3 entries, positive, negative, or blank. It is blank when the patient has not been screened. Here is the sample dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data JANFEB.SAMPLEUNIQUE;
  infile datalines dsd truncover;
  input ID:BEST. LocationType:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,Yes,Positive
2,2,No,
3,3,Yes,Negative
4,1,No,
5,2,Yes,Positive
6,3,No,
7,1,Yes,Negative
8,2,No,
9,3,Yes,Positive
10,1,No,
11,1,Yes,Negative
12,2,Yes,Positive
13,3,Yes,Negative
14,1,No,
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I create a table from this dataset that groups screening and status results in this following way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Location Type&lt;/TD&gt;&lt;TD&gt;Screened&lt;/TD&gt;&lt;TD&gt;Positive&lt;/TD&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;TD&gt;Screening Rate&lt;/TD&gt;&lt;TD&gt;Positive Prevalence&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;30%&lt;/TD&gt;&lt;TD&gt;7%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;20%&lt;/TD&gt;&lt;TD&gt;8%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;50%&lt;/TD&gt;&lt;TD&gt;10%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the explanation of the columns:&lt;/P&gt;&lt;P&gt;- Screened: Unique count under each location type where the screened variable had 'Yes' in it.&lt;/P&gt;&lt;P&gt;- Positive: Unique count under each location type where the status variable had 'Positive' in it.&lt;/P&gt;&lt;P&gt;- Total: Unique count under each location type in the dataset.&lt;/P&gt;&lt;P&gt;- Screening rate: Screened/Total&lt;/P&gt;&lt;P&gt;- Positive prevalence; Positive/Screen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 08:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352745#M82256</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T08:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new table with unique counts and percentage of an old table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352753#M82262</link>
      <description>&lt;P&gt;Your test data doesn't match your example output, or if it does, eplain how a count of 3 id's can yield 30? &amp;nbsp;Anyways this should get you started:&lt;/P&gt;
&lt;PRE&gt;data sampleunique;
  infile datalines dsd truncover;
  input ID:BEST. LocationType:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,Yes,Positive
2,2,No,
3,3,Yes,Negative
4,1,No,
5,2,Yes,Positive
6,3,No,
7,1,Yes,Negative
8,2,No,
9,3,Yes,Positive
10,1,No,
11,1,Yes,Negative
12,2,Yes,Positive
13,3,Yes,Negative
14,1,No,
;;;;
run;

proc sql;
  create table WANT as
  select  LOCATIONTYPE,
          sum(case when SCREEN="Yes" then 1 else 0 end) as SCREENED,
          sum(case when char(RESULT,1)="P" then 1 else 0 end) as POSITIVE,
          count(*) as TOTAL,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    SAMPLEUNIQUE
  group by LOCATIONTYPE;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 08:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352753#M82262</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-24T08:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a new table with unique counts and percentage of an old table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352764#M82265</link>
      <description>&lt;P&gt;You're right. The output doesn't match those numbers. I just arbitrarily put in numbers for the sake of creating a sample output of what I would like it to look like. Your code works! Thanks so much.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 09:28:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-new-table-with-unique-counts-and-percentage-of-an-old/m-p/352764#M82265</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T09:28:52Z</dc:date>
    </item>
  </channel>
</rss>

