<?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 SAS code for counting cases/control  for unique id_idchem combinations in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614676#M8577</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please, could someone help me with the SAS code to verify the count(frequency) of ca case ca cont pop cont for each unique/distinct id and idchem combination. I have&amp;nbsp; 29 obs, 3 pollutants idchem 990005=cla_exp, 990021 = bio_exp and 210701 = amo_exp. I need to count the number of the lung variables associated with each unique id_idchem combination. For obs 2 (Osaa13-idchem 210701) has 1 lung ca case. Same with obs 4 so I expect SAS to count obs 2 &amp;amp; 4 as frequency of 1 since they have the same id_idchem combination.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, I would like the overall freq of unique id_idchem by lung for 210701 to be 2/8 for ca case (for example).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My SAS output Tables 1 &amp;amp; 2 are attached. The SAS code and log are found below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;73 data mg1b; set mgp(obs=29);&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1577892267242" class="sasNote"&gt;NOTE: There were 29 observations read from the data set WORK.MGP.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1577892267242" class="sasNote"&gt;NOTE: The data set WORK.MG1B has 29 observations and 4 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1577892267242" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 proc print data=mg1b;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 Title " Table 1: Exposure to 3 pollutants";&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote4_1577892267242" class="sasNote"&gt;NOTE: There were 29 observations read from the data set WORK.MG1B.&lt;/DIV&gt;
&lt;DIV id="sasLogNote5_1577892267242" class="sasNote"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.27 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.27 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 proc freq data=mg1b;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78 tables idchem*lung;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 Title" Table 2: Frequency: id_idchem vs case/control for 3 pollutants "; run;&lt;/DIV&gt;
&lt;DIV id="sasLogNote6_1577892267242" class="sasNote"&gt;NOTE: There were 29 observations read from the data set WORK.MG1B.&lt;/DIV&gt;
&lt;DIV id="sasLogNote7_1577892267242" class="sasNote"&gt;NOTE: PROCEDURE FREQ used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.21 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.20 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;80&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;81 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;93&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Thanks very much.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;ak.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE id="pre_sasLog_1094" class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Jan 2020 15:49:22 GMT</pubDate>
    <dc:creator>ak2011</dc:creator>
    <dc:date>2020-01-01T15:49:22Z</dc:date>
    <item>
      <title>SAS code for counting cases/control  for unique id_idchem combinations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614676#M8577</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please, could someone help me with the SAS code to verify the count(frequency) of ca case ca cont pop cont for each unique/distinct id and idchem combination. I have&amp;nbsp; 29 obs, 3 pollutants idchem 990005=cla_exp, 990021 = bio_exp and 210701 = amo_exp. I need to count the number of the lung variables associated with each unique id_idchem combination. For obs 2 (Osaa13-idchem 210701) has 1 lung ca case. Same with obs 4 so I expect SAS to count obs 2 &amp;amp; 4 as frequency of 1 since they have the same id_idchem combination.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, I would like the overall freq of unique id_idchem by lung for 210701 to be 2/8 for ca case (for example).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My SAS output Tables 1 &amp;amp; 2 are attached. The SAS code and log are found below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasSource"&gt;73 data mg1b; set mgp(obs=29);&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1577892267242" class="sasNote"&gt;NOTE: There were 29 observations read from the data set WORK.MGP.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1577892267242" class="sasNote"&gt;NOTE: The data set WORK.MG1B has 29 observations and 4 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1577892267242" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.01 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 proc print data=mg1b;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 Title " Table 1: Exposure to 3 pollutants";&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="sasLogNote4_1577892267242" class="sasNote"&gt;NOTE: There were 29 observations read from the data set WORK.MG1B.&lt;/DIV&gt;
&lt;DIV id="sasLogNote5_1577892267242" class="sasNote"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.27 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.27 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 proc freq data=mg1b;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78 tables idchem*lung;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 Title" Table 2: Frequency: id_idchem vs case/control for 3 pollutants "; run;&lt;/DIV&gt;
&lt;DIV id="sasLogNote6_1577892267242" class="sasNote"&gt;NOTE: There were 29 observations read from the data set WORK.MG1B.&lt;/DIV&gt;
&lt;DIV id="sasLogNote7_1577892267242" class="sasNote"&gt;NOTE: PROCEDURE FREQ used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.21 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.20 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;80&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;81 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;93&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Thanks very much.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;ak.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE id="pre_sasLog_1094" class="sasLog"&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 15:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614676#M8577</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2020-01-01T15:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code for counting cases/control  for unique id_idchem combinations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614678#M8578</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/190754"&gt;@ak2011&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy new year!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest that you run a PROC SORT with the NODUPKEY option before running the PROC FREQ:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = env out = env_distinct nodupkey;
	by lung id_idchem;
run;
proc freq data = env_distinct;
	table lung * idchem / nocol norow nocol nopercent;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does that give you the expected results?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 17:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614678#M8578</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-01-01T17:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code for counting cases/control  for unique id_idchem combinations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614682#M8580</link>
      <description>&lt;P&gt;proc sort with NODUPKEY is useful, but depending on the size of the data set, can be expensive. &amp;nbsp; In this case, I'd suggest two proc freqs.&amp;nbsp; The first produces a data set FREQS of frequencies of IDCHEM*LUNG&amp;nbsp; (i.e. one obs for each combination with 2 additional variables COUNT and PERCENT).&amp;nbsp; Then submit the new dataset to a proc freq with the same tables specification.&amp;nbsp; This will yield counts of non-empty combinations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data =mgp noprint;
  tables idchem * lung /out=freqs;
run;
proc freq data=freqs;
  tables idchem * lung / norow nocol;
run;
&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;The advantage here is that proc freq doesn't need a sorted data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jan 2020 18:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614682#M8580</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-01T18:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS code for counting cases/control  for unique id_idchem combinations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614728#M8586</link>
      <description>Thanks very much. It works!&lt;BR /&gt;ak.</description>
      <pubDate>Thu, 02 Jan 2020 11:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/SAS-code-for-counting-cases-control-for-unique-id-idchem/m-p/614728#M8586</guid>
      <dc:creator>ak2011</dc:creator>
      <dc:date>2020-01-02T11:32:09Z</dc:date>
    </item>
  </channel>
</rss>

