<?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 an alternative table from unique counts and rates from original dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352912#M82333</link>
    <description>&lt;P&gt;I did a roundabout way of getting to your solution. I separated genders into two different tables and then merged them together and proc sort them according to age range and gender. I'm not sure what exactly happened though. The output of your code and mine are off. Do you know what is wrong with the code? I added a bigger dataset so that all age ranges for all genders would have some kind of entry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*extended sample dataset of 30 entries*/

data sampleunique;
  infile datalines dsd truncover;
  input ID:BEST. Gender:BEST. AgeRange:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,1,Yes,Positive
2,2,2,No,
3,1,3,Yes,Negative
4,2,4,No,
5,1,5,Yes,Positive
6,2,6,No,
7,1,1,Yes,Negative
8,2,2,No,
9,1,3,Yes,Positive
10,2,4,No,
11,1,5,Yes,Negative
12,2,6,Yes,Positive
13,1,1,Yes,Negative
14,2,3,Yes,Positive
15,1,1,Yes,Negative
16,1,2,Yes,Negative
17,1,3,Yes,Negative
18,1,4,No,
19,1,5,No,
20,1,6,No,
21,2,1,No,
22,2,2,No,
23,2,3,No,
24,2,4,No,
25,2,5,Yes,Positive
26,2,6,Yes,Positive
27,2,1,Yes,Positive
28,2,6,Yes,Negative
29,1,3,Yes,Negative
30,2,1,Yes,Positive
;;;;

/*this was your code*/

proc sql;
  create table WANT as
  select  AGERANGE,
          GENDER,
          count(case when char(RESULT,1)="P" then 1 else 0 end) as POSITIVE,
          count(case when char(SCREEN,1)="Y" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          CALCULATED TOTAL - CALCULATED SCREENED as TOTAL_SCREEN_DIFF,
          CALCULATED SCREENED - CALCULATED POSITIVE as SCREEN_POS_DIFF,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREEN_RATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POS_PREV
  from    SAMPLEUNIQUE
  group by AGERANGE,
           GENDER;
quit;

/*this is mine*/

proc sql;
  create table sampleMALE as
  select  agerange,
  		  sum(case when char(result,1)="P" then 1 else 0 end) as POSITIVE,
          sum(case when screen="Yes" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          (CALCULATED TOTAL - CALCULATED SCREENED) as TotalScreenedDifference,
          (CALCULATED SCREENED - CALCULATED POSITIVE) as ScreenedPositiveDifference,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    sampleunique
  where gender=1
  group by agerange;
quit;

data samplemale;
set samplemale;
gender=1;
run;

proc sql;
  create table sampleFEMALE as
  select  agerange,
  		  sum(case when char(result,1)="P" then 1 else 0 end) as POSITIVE,
          sum(case when screen="Yes" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          (CALCULATED TOTAL - CALCULATED SCREENED) as TotalScreenedDifference,
          (CALCULATED SCREENED - CALCULATED POSITIVE) as ScreenedPositiveDifference,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    sampleunique
  where gender=2
  group by agerange;
quit;

data sampleFEMALE;
set sampleFEMALE;
Gender=2;
run;

data sampleMERGE;
retain agerange gender positive;
set sampleMALE sampleFEMALE;
run;

proc sort data=sampleMERGE;
by agerange gender;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 24 Apr 2017 15:18:02 GMT</pubDate>
    <dc:creator>byeh2017</dc:creator>
    <dc:date>2017-04-24T15:18:02Z</dc:date>
    <item>
      <title>Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352769#M82268</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello. I have a dataset that contains 5 variables. "ID" is a unique identifier of a person in my dataset. "Gender" is male (1) or female (2). AgeRange contains only 1 through 6, which indicates which age range they fall into based on a categorical scheme for my report. "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;/SPAN&gt;&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;data JANFEB.SAMPLEUNIQUE;
  infile datalines dsd truncover;
  input ID:BEST. Gender:BEST. AgeRange:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,1,Yes,Positive
2,2,2,No,
3,1,3,Yes,Negative
4,2,4,No,
5,1,5,Yes,Positive
6,2,6,No,
7,1,1,Yes,Negative
8,2,2,No,
9,1,3,Yes,Positive
10,2,4,No,
11,1,5,Yes,Negative
12,2,6,Yes,Positive
13,1,1,Yes,Negative
14,2,3,Yes,Positive
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do I create a table from this dataset that groups screening and status results in this following way? I would like to primarily group my new data table by age range (1-6) and gender (1-2).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Age Range&lt;/TD&gt;&lt;TD&gt;Gender&lt;/TD&gt;&lt;TD&gt;Positive&lt;/TD&gt;&lt;TD&gt;Screened&lt;/TD&gt;&lt;TD&gt;All&lt;/TD&gt;&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;&lt;TD&gt;335&lt;/TD&gt;&lt;TD&gt;1388&lt;/TD&gt;&lt;TD&gt;83%&lt;/TD&gt;&lt;TD&gt;12.5%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;42&lt;/TD&gt;&lt;TD&gt;1132&lt;/TD&gt;&lt;TD&gt;1413&lt;/TD&gt;&lt;TD&gt;281&lt;/TD&gt;&lt;TD&gt;1090&lt;/TD&gt;&lt;TD&gt;80%&lt;/TD&gt;&lt;TD&gt;3.7%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;179&lt;/TD&gt;&lt;TD&gt;3902&lt;/TD&gt;&lt;TD&gt;4793&lt;/TD&gt;&lt;TD&gt;891&lt;/TD&gt;&lt;TD&gt;3723&lt;/TD&gt;&lt;TD&gt;81%&lt;/TD&gt;&lt;TD&gt;4.6%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;175&lt;/TD&gt;&lt;TD&gt;3932&lt;/TD&gt;&lt;TD&gt;4862&lt;/TD&gt;&lt;TD&gt;930&lt;/TD&gt;&lt;TD&gt;3757&lt;/TD&gt;&lt;TD&gt;81%&lt;/TD&gt;&lt;TD&gt;4.5%&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;- Positive: Unique count under each age range and specific gender where the status variable had 'Positive' in it.&lt;/P&gt;&lt;P&gt;- Screened: Unique count under each &lt;SPAN&gt;age range and specific gender&lt;/SPAN&gt;&amp;nbsp;where the screened variable had 'Yes' in it.&lt;/P&gt;&lt;P&gt;- All: Unique count under each &lt;SPAN&gt;age range and specific gender&lt;/SPAN&gt;&amp;nbsp;in the dataset.&lt;/P&gt;&lt;P&gt;- All Screened Difference: All - Screened&lt;/P&gt;&lt;P&gt;-&amp;nbsp;&lt;SPAN&gt;Screened Positive Difference: Screened - Positive&lt;/SPAN&gt;&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;Thanks so much for your help!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 09:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352769#M82268</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T09:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352773#M82270</link>
      <description>&lt;P&gt;Exactly the same as in this post:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352769" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352769&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;You just change the groups?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 09:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352773#M82270</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-24T09:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352776#M82271</link>
      <description>&lt;P&gt;I got most of the code to work, but not quite sure how to group genders in. Whenenver I select agerange and gender and group by the same two variables, the table creates 31,000+ entries.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using my real dataset in here, so the variables are a bit different&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table janfeb.Janhosptypescreeningresults as
  select  agerange,
  		  sum(case when char(hcvresult,1)="P" then 1 else 0 end) as POSITIVE,
          sum(case when hcvscreening="Yes" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          (CALCULATED TOTAL - CALCULATED SCREENED) as TotalScreenedDifference,
          (CALCULATED SCREENED - CALCULATED POSITIVE) as ScreenedPositiveDifference,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    janfeb.jfgmi
  where dcdeathdate &amp;gt;= dhms(mdy(02,01,2017),0,0,0) and dcdeathdate &amp;lt;= dhms(mdy(02,28,2017),0,0,0)
  group by agerange;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How do I include the count for agerange and gender into this new table? Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 10:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352776#M82271</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T10:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352778#M82272</link>
      <description>&lt;P&gt;Mabye restart your question by asking what it is your actually trying to do. &amp;nbsp;From what you have said it sounds like your creating a table based on demography data. &amp;nbsp;The simplest way to do this would be to do a proc freq on your data, then post process the resulting output from that, something like:&lt;/P&gt;
&lt;PRE&gt;data SAMPLEUNIQUE;
  infile datalines dsd truncover;
  input ID:BEST. Gender:BEST. AgeRange:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,1,Yes,Positive
2,2,2,No,
3,1,3,Yes,Negative
4,2,4,No,
5,1,5,Yes,Positive
6,2,6,No,
7,1,1,Yes,Negative
8,2,2,No,
9,1,3,Yes,Positive
10,2,4,No,
11,1,5,Yes,Negative
12,2,6,Yes,Positive
13,1,1,Yes,Negative
14,2,3,Yes,Positive
;;;;
run;

proc freq data=sampleunique noprint;
  tables gender * agerange * screen * result / out=want;
run;&lt;/PRE&gt;
&lt;P&gt;The want table can then be transposed up if needed, and you can add screening counts to that and then calculate the percentages.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 10:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352778#M82272</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-24T10:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352832#M82301</link>
      <description>&lt;P&gt;Thanks for your suggestions. How do I transpose it and add the difference and percentages? I proc freq that table and got this dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.WANT;
  infile datalines dsd truncover;
  input agerange:32. gender:$1. HCVScreening:$9. HCVresult:$27. COUNT:32. PERCENT:32.;
datalines4;
1,1,No,,1114,
1,1,No,Negative,41,0.1619209352
1,1,Yes,Negative,2770,10.939536353
1,1,Yes,Positive,10,0.039492911
1,2,No,,931,
1,2,No,Negative,46,0.1816673907
1,2,Yes,Negative,2319,9.1584060661
1,2,Yes,Positive,6,0.0236957466
2,1,,,1,
2,1,No,,193,
2,1,No,Negative,18,0.0710872398
2,1,No,Positive,2,0.0078985822
2,1,Yes,Negative,1147,4.5298368943
2,1,Yes,Positive,25,0.0987322776
2,2,No,,389,
2,2,No,Negative,105,0.4146755657
2,2,Yes,Negative,3076,12.148019431
2,2,Yes,Positive,22,0.0868844042
3,1,,,1,
3,1,No,,173,
3,1,No,Negative,23,0.0908336954
3,1,No,Positive,1,0.0039492911
3,1,Yes,Negative,860,3.3963903479
3,1,Yes,Positive,91,0.3593854903
3,2,No,,314,
3,2,No,Negative,72,0.2843489594
3,2,Yes,Negative,1796,7.0929268196
3,2,Yes,Positive,39,0.154022353
4,1,,,4,
4,1,No,,221,
4,1,No,Negative,18,0.0710872398
4,1,No,Positive,1,0.0039492911
4,1,Yes,Negative,884,3.4911733344
4,1,Yes,Positive,189,0.7464160183
4,2,No,,195,
4,2,No,Negative,50,0.1974645551
4,2,Yes,Negative,918,3.6254492319
4,2,Yes,Positive,27,0.1066308598
5,1,,,3,
5,1,No,,305,
5,1,No,Negative,27,0.1066308598
5,1,Yes,Negative,1388,5.4816160499
5,1,Yes,Positive,198,0.7819596382
5,2,No,,241,
5,2,No,Negative,40,0.1579716441
5,2,Yes,Negative,1090,4.3047273014
5,2,Yes,Positive,42,0.1658702263
6,1,,,2,
6,1,No,,825,
6,1,No,Negative,62,0.2448560483
6,1,Yes,Negative,3725,14.711109356
6,1,Yes,Positive,179,0.7069231073
6,2,,,1,
6,2,No,,846,
6,2,No,Negative,82,0.3238418704
6,2,Yes,,1,
6,2,Yes,Negative,3757,14.837486671
6,2,Yes,Positive,175,0.6911259429
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Is there no way to do this on proc sql? I tried to select and group by agerange and gender, but it gave me 31,000 entries. Not quite sure what happened.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 13:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352832#M82301</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T13:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352839#M82305</link>
      <description>&lt;P&gt;Well, you could do it in SQL, it just becomes a bit fiddly see below. &amp;nbsp;Thats why its easier to do a proc freq, then in datastep move your data up (see methods to reshape data, a ton of results on Google). &amp;nbsp;Note your test data doesn't seem to have any differences in it or maybe I misunderstand the total?&lt;/P&gt;
&lt;PRE&gt;data SAMPLEUNIQUE;
  infile datalines dsd truncover;
  input ID:BEST. Gender:BEST. AgeRange:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,1,Yes,Positive
2,2,2,No,
3,1,3,Yes,Negative
4,2,4,No,
5,1,5,Yes,Positive
6,2,6,No,
7,1,1,Yes,Negative
8,2,2,No,
9,1,3,Yes,Positive
10,2,4,No,
11,1,5,Yes,Negative
12,2,6,Yes,Positive
13,1,1,Yes,Negative
14,2,3,Yes,Positive
;;;;
run;

proc sql;
  create table WANT as
  select  AGERANGE,
          GENDER,
          count(case when char(RESULT,1)="P" then 1 else 0 end) as POSITIVE,
          count(case when char(SCREEN,1)="Y" then 1 else 0 end) as SCREENED,
          count(*) as ALL,
          CALCULATED ALL - CALCULATED SCREENED as ALL_DIFF,
          CALCULATED SCREENED - CALCULATED POSITIVE as SCREEN_POS_DIFF,
          (CALCULATED SCREENED / CALCULATED ALL) * 100 as SCREEN_RATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POS_PREV
  from    SAMPLEUNIQUE
  group by AGERANGE,
           GENDER;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 13:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352839#M82305</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-24T13:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352902#M82330</link>
      <description>&lt;P&gt;There are no differences in the test data. The difference variables are basically the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All_Screened_Diff= Distinct count of EVERYONE in that agerange and gender minus distinct count of those SCREENED&amp;nbsp;&lt;SPAN&gt;in that agerange and gender&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Screened_Pos_Diff=&amp;nbsp;&lt;SPAN&gt;Distinct count of SCREENED in that agerange and gender minus distinct count of those POSITIVE in result&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;in that agerange and gender&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 15:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352902#M82330</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T15:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352912#M82333</link>
      <description>&lt;P&gt;I did a roundabout way of getting to your solution. I separated genders into two different tables and then merged them together and proc sort them according to age range and gender. I'm not sure what exactly happened though. The output of your code and mine are off. Do you know what is wrong with the code? I added a bigger dataset so that all age ranges for all genders would have some kind of entry.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*extended sample dataset of 30 entries*/

data sampleunique;
  infile datalines dsd truncover;
  input ID:BEST. Gender:BEST. AgeRange:BEST. Screen:$3. Result:$8.;
datalines4;
1,1,1,Yes,Positive
2,2,2,No,
3,1,3,Yes,Negative
4,2,4,No,
5,1,5,Yes,Positive
6,2,6,No,
7,1,1,Yes,Negative
8,2,2,No,
9,1,3,Yes,Positive
10,2,4,No,
11,1,5,Yes,Negative
12,2,6,Yes,Positive
13,1,1,Yes,Negative
14,2,3,Yes,Positive
15,1,1,Yes,Negative
16,1,2,Yes,Negative
17,1,3,Yes,Negative
18,1,4,No,
19,1,5,No,
20,1,6,No,
21,2,1,No,
22,2,2,No,
23,2,3,No,
24,2,4,No,
25,2,5,Yes,Positive
26,2,6,Yes,Positive
27,2,1,Yes,Positive
28,2,6,Yes,Negative
29,1,3,Yes,Negative
30,2,1,Yes,Positive
;;;;

/*this was your code*/

proc sql;
  create table WANT as
  select  AGERANGE,
          GENDER,
          count(case when char(RESULT,1)="P" then 1 else 0 end) as POSITIVE,
          count(case when char(SCREEN,1)="Y" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          CALCULATED TOTAL - CALCULATED SCREENED as TOTAL_SCREEN_DIFF,
          CALCULATED SCREENED - CALCULATED POSITIVE as SCREEN_POS_DIFF,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREEN_RATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POS_PREV
  from    SAMPLEUNIQUE
  group by AGERANGE,
           GENDER;
quit;

/*this is mine*/

proc sql;
  create table sampleMALE as
  select  agerange,
  		  sum(case when char(result,1)="P" then 1 else 0 end) as POSITIVE,
          sum(case when screen="Yes" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          (CALCULATED TOTAL - CALCULATED SCREENED) as TotalScreenedDifference,
          (CALCULATED SCREENED - CALCULATED POSITIVE) as ScreenedPositiveDifference,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    sampleunique
  where gender=1
  group by agerange;
quit;

data samplemale;
set samplemale;
gender=1;
run;

proc sql;
  create table sampleFEMALE as
  select  agerange,
  		  sum(case when char(result,1)="P" then 1 else 0 end) as POSITIVE,
          sum(case when screen="Yes" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          (CALCULATED TOTAL - CALCULATED SCREENED) as TotalScreenedDifference,
          (CALCULATED SCREENED - CALCULATED POSITIVE) as ScreenedPositiveDifference,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    sampleunique
  where gender=2
  group by agerange;
quit;

data sampleFEMALE;
set sampleFEMALE;
Gender=2;
run;

data sampleMERGE;
retain agerange gender positive;
set sampleMALE sampleFEMALE;
run;

proc sort data=sampleMERGE;
by agerange gender;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Apr 2017 15:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352912#M82333</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T15:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352939#M82338</link>
      <description>&lt;P&gt;You should not put where clauses with group by's. &amp;nbsp;If you need to restrict it then (select * from have where xyz) subquery it. &amp;nbsp;As for different counts, sure your doing different grouping, you will get different output?&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 16:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352939#M82338</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-04-24T16:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an alternative table from unique counts and rates from original dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352967#M82345</link>
      <description>&lt;P&gt;Thanks. How would you put the where statement here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table janfeb.Febscreeningresults as
  select  agerange, gender,
  		  sum(case when char(hcvresult,1)="P" then 1 else 0 end) as POSITIVE,
          sum(case when hcvscreening="Yes" then 1 else 0 end) as SCREENED,
          count(*) as TOTAL,
          (CALCULATED TOTAL - CALCULATED SCREENED) as TotalScreenedDifference,
          (CALCULATED SCREENED - CALCULATED POSITIVE) as ScreenedPositiveDifference,
          (CALCULATED SCREENED / CALCULATED TOTAL) * 100 as SCREENINGRATE,
          (CALCULATED POSITIVE / CALCULATED SCREENED) * 100 as POSITIVEPREVALENCE
  from    janfeb.jfgmi
  where dcdeathdate &amp;gt;= dhms(mdy(02,01,2017),0,0,0) and dcdeathdate &amp;lt;= dhms(mdy(02,28,2017),0,0,0)
  group by agerange, gender;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It seems to work fine on sas when i put the where statement below the from statement. Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2017 18:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-an-alternative-table-from-unique-counts-and-rates-from/m-p/352967#M82345</guid>
      <dc:creator>byeh2017</dc:creator>
      <dc:date>2017-04-24T18:21:45Z</dc:date>
    </item>
  </channel>
</rss>

