<?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: Counting number of qualifying observations in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419896#M4161</link>
    <description>&lt;P&gt;Create a array with boolean (0 or 1) values for the possible occurences, in your case&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array has{10} has0-has9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run a do loop through your numeric variables (define another array for all numeric variables for that) and set your boolean values accordingly.&lt;/P&gt;
&lt;P&gt;After that, you can use freq or tabulate on your hasX variables, as needed.&lt;/P&gt;</description>
    <pubDate>Sun, 10 Dec 2017 08:50:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-12-10T08:50:08Z</dc:date>
    <item>
      <title>Counting number of qualifying observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419891#M4160</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I’m trying to figure out how to create the output below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data:&lt;/P&gt;&lt;P&gt;A 1 2 4 7&lt;/P&gt;&lt;P&gt;B 0 2 3 8&lt;/P&gt;&lt;P&gt;C 4 2 6 3&lt;/P&gt;&lt;P&gt;D 7 4 5 2&lt;/P&gt;&lt;P&gt;E 1 9 6 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Number of&amp;nbsp;observations that have a 4 or a 7? (3)&lt;/P&gt;&lt;P&gt;What I’m NOT looking for is the frequency of a 4 or 7 (5)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bonus:&lt;/P&gt;&lt;P&gt;How to produce a single output that will provide data on the above case, but for multple criteria at a time, in one function.&amp;nbsp; E.g. -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Number of&amp;nbsp;observations that have a 4 or a 7? (3)&lt;/P&gt;&lt;P&gt;Number of observations&amp;nbsp;that have a 2? (4)&lt;/P&gt;&lt;P&gt;Number of&amp;nbsp;observations that have a 3 or 8? (3)&lt;/P&gt;&lt;P&gt;Etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much thanks!!&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 07:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419891#M4160</guid>
      <dc:creator>jsheu</dc:creator>
      <dc:date>2017-12-10T07:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of qualifying observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419896#M4161</link>
      <description>&lt;P&gt;Create a array with boolean (0 or 1) values for the possible occurences, in your case&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array has{10} has0-has9;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Run a do loop through your numeric variables (define another array for all numeric variables for that) and set your boolean values accordingly.&lt;/P&gt;
&lt;P&gt;After that, you can use freq or tabulate on your hasX variables, as needed.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 08:50:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419896#M4161</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-12-10T08:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of qualifying observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419949#M4162</link>
      <description>&lt;P&gt;You could get a much better answer if you spell out what the conditions are.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are starting with a SAS data set, what are the variable names?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should the result be a SAS data set with just one observation in it?&amp;nbsp; A report?&amp;nbsp; What exactly are you hoping to get?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The programming isn't hard.&amp;nbsp; But don't ask us to imagine what you are thinking the result would be.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 18:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419949#M4162</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-12-10T18:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of qualifying observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419961#M4163</link>
      <description>&lt;P&gt;If it's only every one or two values you're checking&amp;nbsp;for, look at WHICHN function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Dec 2017 19:18:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/419961#M4163</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-10T19:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of qualifying observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/420025#M4164</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Sample_data;
input ID$ var1-var3;
datalines;
A 1 2 4 7
B 0 2 3 8
C 4 2 6 3
D 7 4 5 2
E 1 9 6 3
;

data _null_;
	set Sample_data end=eof;
	array AnArray{*} var1-var3;
	do i=1 to dim(AnArray);
		if AnArray[i] in (4,7) then do;
			c+1;
			return;
		end;
	end;
	if eof then put "Number of observations that have a 4 or a 7: " c;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Dec 2017 07:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/420025#M4164</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-12-11T07:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Counting number of qualifying observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/420062#M4170</link>
      <description>&lt;P&gt;Convert your set of variables to a string, and then use the indexc function on that string to search for&amp;nbsp;characters represent each of your criteria:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $   var1-var4;
datalines;
A 1 2 4 7
B 0 2 3 8
C 4 2 6 3
D 7 4 5 2
E 1 9 6 3
run;

data _null_;
  set have end=last_case;
  array n {3}                n_47  n_2  n_3;
  array c {3} $2 _temporary_ ('47', '2', '3');
  cat_vars=cats(of var1-var4);
  do v=1 to dim(n);
    n{v}+(indexc(cat_vars,trim(c{v}))&amp;gt;0);
  end;
  if last_case then  put (N_:) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, INDEXC works only when your search criteria are collections of single characters.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition:&amp;nbsp; I started&amp;nbsp;thinking about search for collections of multi-character values, using the same general strategy. Here's an example using the FINDW function. Instead of looking for&amp;nbsp;&amp;nbsp;(a) 4 or 7,&amp;nbsp;(b) 2, or c(3) 3,&amp;nbsp;it looks for 2-digit numbers 14 or 17,&amp;nbsp; 12, or 13:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id $   var1-var4;
datalines;
A 11 12 14 17
B 10 12 13 18
C 14 12 16 13
D 17 14 15 12
E 11 19 16 13
run;

data _null_;
  set have end=last_case;
  array n {3}                 n_1417  n_12  n_13;
  array c {3} $5 _temporary_ ('14 17', '12', '13');

  length cat_vars $20;
  cat_vars=catx(' ',of var1-var4);

  do I=1 to dim(n);
    found=0;
    do J=1 to countw(c{I}) until (found^=0);
      found=findw(cat_vars,scan(c{I},J));
    end;
    n{I}+(found&amp;gt;0);
  end;
  if last_case then  put (N_:) (=);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Dec 2017 11:52:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Counting-number-of-qualifying-observations/m-p/420062#M4170</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-12-11T11:52:25Z</dc:date>
    </item>
  </channel>
</rss>

