<?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: Count of records compared to the average in SAS Visual Analytics</title>
    <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Count-of-records-compared-to-the-average/m-p/867759#M17104</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a tricky one. I think you will need to precalculate the median value as part of your data preparation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VA expression syntax does not like to compare numerics to aggregated measures, so you cannot simply calculate the median (which returns an aggregated measure) and compare that to the number of days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you precalculate the median (using PROC MEANS, for example) as a regular measure column, then you can create an expression based on that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could make your two calculations as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above Average:&lt;/P&gt;
&lt;P&gt;IF ('Number of days'n &amp;gt;= 'Median'n) RETURN 1 ELSE 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below Average:&lt;/P&gt;
&lt;P&gt;IF ('Number of days'n &amp;lt; 'Median'n) RETURN 1 ELSE 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can now apply Sum aggregation to these to get the count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, there might be a better, simpler solution I'm not thinking of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us know if that helps,&lt;/P&gt;
&lt;P&gt;Sam&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Apr 2023 13:18:23 GMT</pubDate>
    <dc:creator>Sam_SAS</dc:creator>
    <dc:date>2023-04-03T13:18:23Z</dc:date>
    <item>
      <title>Count of records compared to the average</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Count-of-records-compared-to-the-average/m-p/867717#M17099</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a start and end date in my data set.&amp;nbsp; I calculated a new item called "number of days" as the number of days in between these two dates. I also calculated the average number of days using the median which is 59. Now, I would like to count how many of my records are above the average number of days and how many are below the average. What would be the calculated item formula for it?&amp;nbsp; For example, assuming I have these 5 records on my dataset:&lt;BR /&gt;&lt;BR /&gt;Number of Days&amp;nbsp;&lt;BR /&gt;110&lt;BR /&gt;100&lt;BR /&gt;45&lt;BR /&gt;55&lt;/P&gt;
&lt;P&gt;25&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, my new calculated item "above average" would have the value 2. and My&amp;nbsp;new calculated item "below average" would have the value 3. So, I could create a key value objects using these values as the measure.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 08:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Count-of-records-compared-to-the-average/m-p/867717#M17099</guid>
      <dc:creator>znhnm</dc:creator>
      <dc:date>2023-04-03T08:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Count of records compared to the average</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/Count-of-records-compared-to-the-average/m-p/867759#M17104</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a tricky one. I think you will need to precalculate the median value as part of your data preparation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VA expression syntax does not like to compare numerics to aggregated measures, so you cannot simply calculate the median (which returns an aggregated measure) and compare that to the number of days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you precalculate the median (using PROC MEANS, for example) as a regular measure column, then you can create an expression based on that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could make your two calculations as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above Average:&lt;/P&gt;
&lt;P&gt;IF ('Number of days'n &amp;gt;= 'Median'n) RETURN 1 ELSE 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below Average:&lt;/P&gt;
&lt;P&gt;IF ('Number of days'n &amp;lt; 'Median'n) RETURN 1 ELSE 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can now apply Sum aggregation to these to get the count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, there might be a better, simpler solution I'm not thinking of.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let us know if that helps,&lt;/P&gt;
&lt;P&gt;Sam&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 13:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/Count-of-records-compared-to-the-average/m-p/867759#M17104</guid>
      <dc:creator>Sam_SAS</dc:creator>
      <dc:date>2023-04-03T13:18:23Z</dc:date>
    </item>
  </channel>
</rss>

