<?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 Count with PROC Means in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308875#M61216</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  infile datalines;
  input list $ NDC discount;
datalines;
Nov 11 50
Dec 12 20
Nov 11 50
May 12 .
Mar 11 30
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;list NDC discount&lt;BR /&gt;&lt;BR /&gt;Nov  11  50
Dec  12  20
Nov  11  50
May  12  .
Mar  11  30&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I want it to look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;list ProductServiceID NDC discount Count_of_NDC
Dec  12               12  20       1
Mar  11               11  30       1
Nov  11               11  50       2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That is, I want to create a count of NDC as well as create a new variable called ProductServiceID that is equal to NDC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This Proc Sql will accomplish this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table mydata2 as
  select list,
         NDC as ProductServiceID,
         NDC,
         discount,
         count(NDC) as Count_of_NDC
	from mydata
	where discount ne .
	group by list,NDC,discount;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I want to do it using proc means or data step or a combination of the two. Please help.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Nov 2016 20:37:35 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2016-11-02T20:37:35Z</dc:date>
    <item>
      <title>Count with PROC Means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308875#M61216</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
  infile datalines;
  input list $ NDC discount;
datalines;
Nov 11 50
Dec 12 20
Nov 11 50
May 12 .
Mar 11 30
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;list NDC discount&lt;BR /&gt;&lt;BR /&gt;Nov  11  50
Dec  12  20
Nov  11  50
May  12  .
Mar  11  30&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I want it to look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;list ProductServiceID NDC discount Count_of_NDC
Dec  12               12  20       1
Mar  11               11  30       1
Nov  11               11  50       2&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;That is, I want to create a count of NDC as well as create a new variable called ProductServiceID that is equal to NDC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This Proc Sql will accomplish this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table mydata2 as
  select list,
         NDC as ProductServiceID,
         NDC,
         discount,
         count(NDC) as Count_of_NDC
	from mydata
	where discount ne .
	group by list,NDC,discount;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I want to do it using proc means or data step or a combination of the two. Please help.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 20:37:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308875#M61216</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-11-02T20:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count with PROC Means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308876#M61217</link>
      <description>&lt;P&gt;Counting is most easily accomplished by PROC FREQ:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tables list * NDC * discount / missing list out=counts (drop=percent rename=(count=Count_of_NDC));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set counts;&lt;/P&gt;
&lt;P&gt;ProductServiceID = NDC;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want to actually print the table, PROC FREQ allows you to add the NOPRINT option.&amp;nbsp; You can choose whether to place it on the PROC statement or at the end of the TABLE statement options.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 20:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308876#M61217</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-11-02T20:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count with PROC Means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308878#M61218</link>
      <description>&lt;P&gt;This should also get you there:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=mydata;
	by list ndc discount;
run;

data want;
	set mydata;
	by list ndc discount;
	where discount ne .;

	if first.discount then
		count=1;
	else
		count+1;

	if last.discount then
		output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Nov 2016 20:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308878#M61218</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-02T20:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count with PROC Means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308883#M61219</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=mydata nway;
   class list ndc discount;
   output out=counts(drop=_type_ rename=(_freq_=Count_of_NDC))
      idgroup(out(ndc)=ProductServiceID);
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/5614iBB787B9DCB3B4A56/image-size/original?v=v2&amp;amp;px=-1" border="0" /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 21:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308883#M61219</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-11-02T21:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count with PROC Means</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308888#M61221</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;&amp;nbsp;Wow you guys are awesome!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 21:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-with-PROC-Means/m-p/308888#M61221</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-11-02T21:27:11Z</dc:date>
    </item>
  </channel>
</rss>

