<?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: Assigning a count value based on distinct values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853336#M337268</link>
    <description>&lt;P&gt;I think what you want is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count (distinct whichc(anrind, 'High', 'Low')) as hlcnt&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Jan 2023 19:18:14 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2023-01-11T19:18:14Z</dc:date>
    <item>
      <title>Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853307#M337258</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I need to assign an analysis flag based partly on this "&lt;SPAN&gt;If a subject has both "High" and "Low" (in ANRIND) within a parameter, set to "Y" for the earliest occurrence of &lt;/SPAN&gt;&lt;STRONG&gt;each value&lt;/STRONG&gt;&lt;SPAN&gt;.". I am using PROC SQL to achieve this using the following code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select *, count(wrstdate) as count
   from have
   where wrstflg is not null 
   group by subjid,paramcd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;This code is not overly important to understand but I'm trying to add this line of code&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum (distinct anrind in ('High','Low') as hlcnt) &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;after count so I&amp;nbsp;get a hlcnt of 2 so I&amp;nbsp;can use it to keep these records when assigning&amp;nbsp;a flag further&amp;nbsp;downstream in the code. However, when I try this it partially&amp;nbsp;works but it also keeps records when there is multiple values of high in different&amp;nbsp;visits or same with multiple values of low which&amp;nbsp;I&amp;nbsp;don't want. I only want to keep it for subjects that have distinct value of high and low.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  SUBJID $ PARAMCD $ VISIT :$30. ANRIND $ WRSTDATE $ WRSTCASE :3. WRSTFLG $; 
infile datalines dlm = '|';
datalines;
1001|AAA|Week 2 |Low|11JUL2022|2|Y
1001|AAA|Week 16|High|11JUL2022|3|Y
1002|BBB|Week 2 |Low|1AUG2022|2|Y
1002|BBB|Week 4 |Low|15AUG2022|2|Y
1003|CCC|Week 2 |High|1AUG2022|3|Y
1003|CCC|Week 4 |High|15AUG2022|3|Y
;
run;

data want;
input  SUBJID $ PARAMCD $ VISIT :$30. ANRIND $ WRSTDATE $ WRSTCASE :3. WRSTFLG $ HLCNT :3.; 
infile datalines dlm = '|';
datalines;
1001|AAA|Week 2 |Low|11JUL2022|2|Y|2
1001|AAA|Week 16|High|11JUL2022|3|Y|2
1002|BBB|Week 2 |Low|1AUG2022|2|Y|1
1002|BBB|Week 4 |Low|15AUG2022|2|Y|1
1003|CCC|Week 2 |High|1AUG2022|3|Y|1
1003|CCC|Week 4 |High|15AUG2022|3|Y|1
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 18:54:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853307#M337258</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2023-01-11T18:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853336#M337268</link>
      <description>&lt;P&gt;I think what you want is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count (distinct whichc(anrind, 'High', 'Low')) as hlcnt&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jan 2023 19:18:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853336#M337268</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-01-11T19:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853347#M337273</link>
      <description>&lt;P&gt;Hi. It's on the right track but not quite right. There are other values in anrind ( e.g 'Normal') and it seems to pick that up in the count.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 20:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853347#M337273</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2023-01-11T20:33:10Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853352#M337276</link>
      <description>&lt;P&gt;And what do you want as a result in such cases?&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 20:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853352#M337276</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-01-11T20:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853353#M337277</link>
      <description>&lt;P&gt;I only want it to pick up a count for distinct values of either 'High' or 'Low' only in any visit per paramcd&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 20:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853353#M337277</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2023-01-11T20:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853354#M337278</link>
      <description>&lt;P&gt;Then try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count (distinct case anrind when 'High' then 1 when 'Low' then 2 else . end) as hlcnt&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Jan 2023 20:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853354#M337278</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-01-11T20:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning a count value based on distinct values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853355#M337279</link>
      <description>&lt;P&gt;That's it! Perfect thank you very much for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2023 21:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-a-count-value-based-on-distinct-values/m-p/853355#M337279</guid>
      <dc:creator>smackerz1988</dc:creator>
      <dc:date>2023-01-11T21:02:24Z</dc:date>
    </item>
  </channel>
</rss>

