<?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 and percentage of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702186#M215063</link>
    <description>&lt;P&gt;Are you only interested in the 'New' type or both new and old?&lt;/P&gt;</description>
    <pubDate>Sat, 28 Nov 2020 15:44:34 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-11-28T15:44:34Z</dc:date>
    <item>
      <title>Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702149#M215047</link>
      <description>&lt;P&gt;Hi Reader,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please let me know how can I get attcahed output data.&lt;/P&gt;
&lt;P&gt;Here is input data :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data abc;&lt;BR /&gt;input cd $ type $;&lt;BR /&gt;cards;&lt;BR /&gt;a new&lt;BR /&gt;a new&lt;BR /&gt;c new&lt;BR /&gt;a old&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;requirement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pdhokriya_0-1606572860186.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52062iAD435D07231BEA64/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pdhokriya_0-1606572860186.png" alt="pdhokriya_0-1606572860186.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;DIV id="tinyMceEditorpdhokriya_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&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>Sat, 28 Nov 2020 14:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702149#M215047</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-28T14:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702174#M215058</link>
      <description>&lt;P&gt;Many of us will not download Microsoft Office files as they are security threats. Please show the desired output in your message.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 12:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702174#M215058</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-28T12:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702177#M215059</link>
      <description>&lt;P&gt;PROC FREQ does counts and percentages.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 13:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702177#M215059</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T13:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702179#M215060</link>
      <description>Posted in my question box</description>
      <pubDate>Sat, 28 Nov 2020 14:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702179#M215060</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-28T14:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702180#M215061</link>
      <description>&lt;P&gt;True, but considering future data this wont work.&lt;BR /&gt;As I wont to get values where records not present like "b", count would be for "a" and "c" records only.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 14:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702180#M215061</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-28T14:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702181#M215062</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/55374"&gt;@pdhokriya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;True, but considering future data this wont work.&lt;BR /&gt;As I wont to get values where records not present like "b", count would be for "a" and "c" records only.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is a case where additional requirements are mentioned after the initial question doesn't mention them. Can you please describe the entire requirements of the problem in one message?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS, several procedures (TABULATE and REPORT and possibly others) allow a PRELOADFMT option which can produce a row of zeros if there are no values for a certain level of a variable.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 15:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702181#M215062</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-28T15:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702186#M215063</link>
      <description>&lt;P&gt;Are you only interested in the 'New' type or both new and old?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 15:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702186#M215063</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-28T15:44:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702435#M215142</link>
      <description>actually both, but its fine if you share for one.</description>
      <pubDate>Mon, 30 Nov 2020 09:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702435#M215142</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-30T09:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702440#M215146</link>
      <description>&lt;P&gt;Ok. Just to be clear, do you want this in a SAS data set or in a report of some sort?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 09:36:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702440#M215146</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-30T09:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702461#M215149</link>
      <description>SAS dataset</description>
      <pubDate>Mon, 30 Nov 2020 10:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702461#M215149</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-30T10:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702463#M215150</link>
      <description>&lt;P&gt;Ok. Here is one way. Let me know if it works for you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc;
input cd $ type $;
cards;
a new
a new
c new
a old
;

proc format;
   value $ fmt 'a' = 'a'
               'b' = 'b'
               'c' = 'c'
   ;
run;

proc summary data = abc nway completetypes;
   class type cd / preloadfmt;
   format cd $fmt.;
   output out = temp(drop = _TYPE_ rename = _FREQ_ = n);
run;

data want(drop = c);
   c = .;
   do until (last.type);
      set temp;
      by type;
      c + n;
   end;
   do until (last.type);
      set temp;
      by type;
      p = divide(n, c);
      output;
   end;
   format p percent8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;type cd n  p 
new  a  2  66.67% 
new  b  0  0.00% 
new  c  1  33.33% 
old  a  1  100.0% 
old  b  0  0.00% 
old  c  0  0.00% &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 10:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702463#M215150</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-30T10:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702471#M215155</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/55374"&gt;@pdhokriya&lt;/a&gt;&amp;nbsp;did this solve your problem?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 11:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702471#M215155</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-30T11:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702484#M215163</link>
      <description>Yes, just a format issue i am getting it. could you please share how to i transpose these.&lt;BR /&gt;&lt;BR /&gt;cd	new_C	new_p	old_c	old_p&lt;BR /&gt;a	2	66.67%	1	1          100.00%&lt;BR /&gt;b	0	0.00%	0	0          0.00%&lt;BR /&gt;c	1	33.33%	0	0          0.00%&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Nov 2020 12:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702484#M215163</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-30T12:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702491#M215168</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data = want;
   by cd;
run;

data want (drop = n p);
   do until (last.cd);
      set want;
      by cd;
      if type = 'new' then do;
         new_n = n;
         new_p = p;
      end;
      else do;
         old_n = n;
         old_p = p;
       end;
   end;
   format new_p old_p percent8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;cd new_n new_p   old_n  old_p 
a  2     66.67%  1      100.0% 
b  0     0.00%   0      0.00% 
c  1     33.33%  0      0.00% &lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Nov 2020 13:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702491#M215168</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-30T13:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count and percentage of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702533#M215182</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; thank you so much for your quck reply. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 30 Nov 2020 15:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-and-percentage-of-data/m-p/702533#M215182</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-30T15:36:36Z</dc:date>
    </item>
  </channel>
</rss>

