<?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 How to calculate with n of the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765306#M242396</link>
    <description>&lt;P&gt;I have a dataset to calculate by the given formulae. Kindly suggest a code to resolve it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input ID Val Type$;
cards;
1 10.5 normal
2 12.4 abnormal
3 16.6 normal
4 10.8 normal
5 13.9 abnormal
6 17.1 normal
7 14.4 abnormal
8 11.2 abnormal
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Formula: count (abnormal)/sum(Val) * 1000 : i.e: 4/51.9*1000&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 11:27:53 GMT</pubDate>
    <dc:creator>Sathish_jammy</dc:creator>
    <dc:date>2021-09-01T11:27:53Z</dc:date>
    <item>
      <title>How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765306#M242396</link>
      <description>&lt;P&gt;I have a dataset to calculate by the given formulae. Kindly suggest a code to resolve it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input ID Val Type$;
cards;
1 10.5 normal
2 12.4 abnormal
3 16.6 normal
4 10.8 normal
5 13.9 abnormal
6 17.1 normal
7 14.4 abnormal
8 11.2 abnormal
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Formula: count (abnormal)/sum(Val) * 1000 : i.e: 4/51.9*1000&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765306#M242396</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2021-09-01T11:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765310#M242400</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With PROC SQL you can do it in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select divide(1000, m)
from (select mean(val) as m from have where type='abnormal');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 11:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765310#M242400</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-09-01T11:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765312#M242402</link>
      <description>&lt;P&gt;What if there are no abnormal types?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 select sum(type='abnormal') as N
      , sum(case when (type='abnormal') then val else . end) as D
      , calculated N/calculated D *1000 as want
   from have 
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;       N         D      want
----------------------------
       4      51.9  77.07129
&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765312#M242402</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-01T12:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765314#M242404</link>
      <description>&lt;P&gt;Do you mean&lt;/P&gt;
&lt;PRE&gt;(count (abnormal) / sum(Val)) * 1000&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;count (abnormal) / (sum(Val) * 1000)&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765314#M242404</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-01T12:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765332#M242413</link>
      <description>&lt;P&gt;What you are asking for is the reciprocal of the mean of VAL for the subgroup type='abnormal'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your task expands to generating such a calculation for many subgroups/many variables, or if you might simultaneously want this for a hierarchy of subgroups, you might consider using PROC SUMMARY followed by a data step.&amp;nbsp; &amp;nbsp;Let's say you want this not only for "abnormal" but also for "normal" and for the entire population, and maybe you have a second variable, NEWVAL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input ID Val Type$;
newval=val + 3*uniform(12531366);
cards;
1 10.5 normal
2 12.4 abnormal
3 16.6 normal
4 10.8 normal
5 13.9 abnormal
6 17.1 normal
7 14.4 abnormal
8 11.2 abnormal
run;

proc summary data=have ;
  class type;
  var  val newval;
  output out=need (where=(_stat_='MEAN'));
run;

data want;
  set need (drop=_:);
  val_result=1000*(1/val);
  newval_result=1000*(1/newval);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run it and take a look at the final and intermediate result datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765332#M242413</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-09-01T12:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765333#M242414</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What if there are no abnormal types?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And what if there is a missing VAL for an abnormal type?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765333#M242414</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-09-01T12:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765352#M242423</link>
      <description>&lt;PRE&gt;data Have;
input ID Val Type$;
cards;
1 10.5 normal
2 12.4 abnormal
3 16.6 normal
4 10.8 normal
5 13.9 abnormal
6 17.1 normal
7 14.4 abnormal
8 11.2 abnormal
;
run;


proc sql;
 select count(val) as N
      , sum(val) as D
      , calculated N/calculated D *1000 as want
   from have 
   	where type='abnormal'
 ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765352#M242423</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-01T13:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765353#M242424</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;data Have;
input ID Val Type$;
cards;
1 10.5 normal
2 12.4 abnormal
3 16.6 normal
4 10.8 normal
5 13.9 abnormal
6 17.1 normal
7 14.4 abnormal
8 11.2 abnormal
;
run;


proc sql;
 select count(*) as N
      , sum(val) as D
      , calculated N/calculated D *1000 as want
   from have 
   	where type='abnormal'
 ;
quit;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For other data sets, which may have missing values of variable VAL, the above code gives the wrong answer, while code using PROC MEANS or PROC SUMMARY still gives the right answer when missing values are present.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765353#M242424</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-01T13:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate with n of the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765355#M242425</link>
      <description>&lt;P&gt;Ha Paige, I just edited my code to fix the problem you are talking about .&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-with-n-of-the-dataset/m-p/765355#M242425</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-01T13:56:50Z</dc:date>
    </item>
  </channel>
</rss>

