<?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: How to conditionally count  observations of variable into  several different new variables with in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292366#M270102</link>
    <description>Thank you very much Reeza! It works!</description>
    <pubDate>Thu, 18 Aug 2016 06:54:59 GMT</pubDate>
    <dc:creator>owenwqp1</dc:creator>
    <dc:date>2016-08-18T06:54:59Z</dc:date>
    <item>
      <title>How to conditionally count  observations of variable into  several different new variables with sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292362#M270099</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my dataset, I have a varialbe with the observation values between 0 and 1, I want to count how many observations of this variable is blow 0.2, how many between 0.2 and 0.5, how many over 0.5. Can I have this done in one sql procedure? If yes, How?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 05:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292362#M270099</guid>
      <dc:creator>owenwqp1</dc:creator>
      <dc:date>2016-08-18T05:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally count  observations of variable into  several different new variables with</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292363#M270100</link>
      <description>&lt;P&gt;You could use&lt;/P&gt;&lt;P&gt;1.)the retain function in the data step and count the values using a series of if conditions or&lt;/P&gt;&lt;P&gt;2.)In proc sql ,probably use the Union&amp;nbsp;option&amp;nbsp;&amp;nbsp;between three individual queries to obtain&amp;nbsp; the counts with the help of group by statments&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 05:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292363#M270100</guid>
      <dc:creator>amanda4286</dc:creator>
      <dc:date>2016-08-18T05:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally count  observations of variable into  several different new variables with</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292364#M270101</link>
      <description>&lt;P&gt;Select&lt;/P&gt;
&lt;P&gt;sum(var&amp;lt;0.2) as lt_2,&lt;/P&gt;
&lt;P&gt;sum(var&amp;gt;=0.2 and var &amp;lt;=0.5) as bet_2_5,&lt;/P&gt;
&lt;P&gt;etc..&lt;/P&gt;
&lt;P&gt;from have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes you can. Sum the condition, if the condition is true it resolves to 1, 0 otherwise.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 06:31:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292364#M270101</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-18T06:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally count  observations of variable into  several different new variables with</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292366#M270102</link>
      <description>Thank you very much Reeza! It works!</description>
      <pubDate>Thu, 18 Aug 2016 06:54:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292366#M270102</guid>
      <dc:creator>owenwqp1</dc:creator>
      <dc:date>2016-08-18T06:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to conditionally count  observations of variable into  several different new variables with</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292367#M270103</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (keep=count_a count_b count_c);
set have end=done;
retain count_a count_a count_c 0;
if var &amp;lt; 0.2 then count_a + 1;
else if var &amp;lt;= 0.5 then count_b + 1;
else count_c + 1;
if done then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Another method is to create a format, so the formatted values can be used in a simple freq:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library=work;
value testfmt
  low-&amp;lt;0.2 = 1
  0.2-0.5 = 2
  0.5&amp;lt;-high = 3
;
run;

data have;
input var;
format var testfmt.;
cards;
.1
.3
.6
.4
.5
.2
.7
;
run;

proc freq data=have order=internal;
tables var / nopercent nocum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 07:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-conditionally-count-observations-of-variable-into-several/m-p/292367#M270103</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-18T07:05:04Z</dc:date>
    </item>
  </channel>
</rss>

