<?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 conditional observations in a DATA step or how to use COUNT () in a DATA step to count in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Count-conditional-observations-in-a-DATA-step-or-how-to-use/m-p/526713#M5146</link>
    <description>&lt;P&gt;I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know I can use PROC SQL to count observations, but I would need to do the same in a DATA step. I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;/P&gt;&lt;P&gt;set HAVE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;count number of observations if return= 0;&lt;/P&gt;&lt;P&gt;zero_ret_perc= (number of observations with zero returns/ total number of observations)*100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much thanks.&lt;/P&gt;</description>
    <pubDate>Sun, 13 Jan 2019 05:55:15 GMT</pubDate>
    <dc:creator>d6k5d3</dc:creator>
    <dc:date>2019-01-13T05:55:15Z</dc:date>
    <item>
      <title>Count conditional observations in a DATA step or how to use COUNT () in a DATA step to count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-conditional-observations-in-a-DATA-step-or-how-to-use/m-p/526713#M5146</link>
      <description>&lt;P&gt;I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know I can use PROC SQL to count observations, but I would need to do the same in a DATA step. I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA want;&lt;/P&gt;&lt;P&gt;set HAVE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;count number of observations if return= 0;&lt;/P&gt;&lt;P&gt;zero_ret_perc= (number of observations with zero returns/ total number of observations)*100;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 05:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-conditional-observations-in-a-DATA-step-or-how-to-use/m-p/526713#M5146</guid>
      <dc:creator>d6k5d3</dc:creator>
      <dc:date>2019-01-13T05:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Count conditional observations in a DATA step or how to use COUNT () in a DATA step to count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-conditional-observations-in-a-DATA-step-or-how-to-use/m-p/526714#M5147</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Sl  Return;
datalines;
 1  4.5563
 2  4.8562
 3  0.0000
 4  3.5879
 5  0.0000
 6  0.0000
 7  0.0000
 8  0.0000
 9  2.5879
10  3.6879
run;


data want;
set have nobs=nobs end=lr;
zero_ret+ return=0;
if lr;
zero_ret_perc= (zero_ret/nobs)*100;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jan 2019 06:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-conditional-observations-in-a-DATA-step-or-how-to-use/m-p/526714#M5147</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-13T06:12:52Z</dc:date>
    </item>
  </channel>
</rss>

