<?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 how many times an observation passes a threshold across variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687723#M208815</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to count how many times an observation passes a certain caloric threshold in the most efficient manner. I have thousands of variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want something similar to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outdata;
set ppp.MFP;
Days_Calorie = N(of Q3	, Q19	, Q33	, Q47	, Q61	, Q75	, Q89	, Q103	, Q117	, Q131	, Q145	, Q159	, Q173	, Q187	, Q201	, Q215	, Q229	, Q243	, Q257	, Q271	, Q285	, Q299	, Q313	, Q327	, Q341	, Q355	, Q369	, Q383	, Q397	, Q411	, Q425	, Q439	, Q453	, Q467	, Q481	, Q495	, Q509	, Q523	, Q537	, Q551	, Q565	, Q579	, Q593	, Q607	, Q621	, Q635	, Q649	, Q663	, Q677	, Q691	, Q705	, Q719	, Q733	, Q747	, Q761	, Q775	, Q789	, Q803	, Q817	, Q831	, Q845	, Q859	, Q873	, Q887	, Q901	, Q915	, Q929	, Q943	, Q957	, Q971	, Q985	, Q999	, Q1013	, Q1027	, Q1041	, Q1055	, Q1069	, Q1083	, Q1097	, Q1111	, Q1125	, Q1139	, Q1153	, Q1167	, Q1181	, Q1195	, Q1209	, Q1223	, Q1237	, Q1251	, Q1265	, Q1279	, Q1293	, Q1307	, Q1321	, Q1335	, Q1349	, Q1363
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I only want to count the occurrence if it passes the &amp;gt;100 threshold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an efficient way to do this? I toyed with the idea similar to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count( Q3	, Q19	, Q33	, Q47	, Q61	, Q75	, Q89	, Q103	, Q117	, Q131	, Q145	, Q159	, Q173	, Q187	, Q201	, Q215	, Q229	, Q243	, Q257	, Q271	, Q285	, Q299	, Q313	, Q327	, Q341	, Q355	, Q369	, Q383	, Q397	, Q411	, Q425	, Q439	, Q453	, Q467	, Q481	, Q495	, Q509	, Q523	, Q537	, Q551	, Q565	, Q579	, Q593	, Q607	, Q621	, Q635	, Q649	, Q663	, Q677	, Q691	, Q705	, Q719	, Q733	, Q747	, Q761	, Q775	, Q789	, Q803	, Q817	, Q831	, Q845	, Q859	, Q873	, Q887	, Q901	, Q915	, Q929	, Q943	, Q957	, Q971	, Q985	, Q999	, Q1013	, Q1027	, Q1041	, Q1055	, Q1069	, Q1083	, Q1097	, Q1111	, Q1125	, Q1139	, Q1153	, Q1167	, Q1181	, Q1195	, Q1209	, Q1223	, Q1237	, Q1251	, Q1265	, Q1279	, Q1293	, Q1307	, Q1321	, Q1335	, Q1349	, Q1363
) as N_obs
from ppp.MFP
where ( Q3	, Q19	, Q33	, Q47	, Q61	, Q75	, Q89	, Q103	, Q117	, Q131	, Q145	, Q159	, Q173	, Q187	, Q201	, Q215	, Q229	, Q243	, Q257	, Q271	, Q285	, Q299	, Q313	, Q327	, Q341	, Q355	, Q369	, Q383	, Q397	, Q411	, Q425	, Q439	, Q453	, Q467	, Q481	, Q495	, Q509	, Q523	, Q537	, Q551	, Q565	, Q579	, Q593	, Q607	, Q621	, Q635	, Q649	, Q663	, Q677	, Q691	, Q705	, Q719	, Q733	, Q747	, Q761	, Q775	, Q789	, Q803	, Q817	, Q831	, Q845	, Q859	, Q873	, Q887	, Q901	, Q915	, Q929	, Q943	, Q957	, Q971	, Q985	, Q999	, Q1013	, Q1027	, Q1041	, Q1055	, Q1069	, Q1083	, Q1097	, Q1111	, Q1125	, Q1139	, Q1153	, Q1167	, Q1181	, Q1195	, Q1209	, Q1223	, Q1237	, Q1251	, Q1265	, Q1279	, Q1293	, Q1307	, Q1321	, Q1335	, Q1349	, Q1363
) &amp;gt;800;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am missing a key concept here, but I think it is close.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 05:15:33 GMT</pubDate>
    <dc:creator>joebacon</dc:creator>
    <dc:date>2020-09-30T05:15:33Z</dc:date>
    <item>
      <title>Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687723#M208815</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to count how many times an observation passes a certain caloric threshold in the most efficient manner. I have thousands of variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want something similar to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outdata;
set ppp.MFP;
Days_Calorie = N(of Q3	, Q19	, Q33	, Q47	, Q61	, Q75	, Q89	, Q103	, Q117	, Q131	, Q145	, Q159	, Q173	, Q187	, Q201	, Q215	, Q229	, Q243	, Q257	, Q271	, Q285	, Q299	, Q313	, Q327	, Q341	, Q355	, Q369	, Q383	, Q397	, Q411	, Q425	, Q439	, Q453	, Q467	, Q481	, Q495	, Q509	, Q523	, Q537	, Q551	, Q565	, Q579	, Q593	, Q607	, Q621	, Q635	, Q649	, Q663	, Q677	, Q691	, Q705	, Q719	, Q733	, Q747	, Q761	, Q775	, Q789	, Q803	, Q817	, Q831	, Q845	, Q859	, Q873	, Q887	, Q901	, Q915	, Q929	, Q943	, Q957	, Q971	, Q985	, Q999	, Q1013	, Q1027	, Q1041	, Q1055	, Q1069	, Q1083	, Q1097	, Q1111	, Q1125	, Q1139	, Q1153	, Q1167	, Q1181	, Q1195	, Q1209	, Q1223	, Q1237	, Q1251	, Q1265	, Q1279	, Q1293	, Q1307	, Q1321	, Q1335	, Q1349	, Q1363
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I only want to count the occurrence if it passes the &amp;gt;100 threshold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an efficient way to do this? I toyed with the idea similar to this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select count( Q3	, Q19	, Q33	, Q47	, Q61	, Q75	, Q89	, Q103	, Q117	, Q131	, Q145	, Q159	, Q173	, Q187	, Q201	, Q215	, Q229	, Q243	, Q257	, Q271	, Q285	, Q299	, Q313	, Q327	, Q341	, Q355	, Q369	, Q383	, Q397	, Q411	, Q425	, Q439	, Q453	, Q467	, Q481	, Q495	, Q509	, Q523	, Q537	, Q551	, Q565	, Q579	, Q593	, Q607	, Q621	, Q635	, Q649	, Q663	, Q677	, Q691	, Q705	, Q719	, Q733	, Q747	, Q761	, Q775	, Q789	, Q803	, Q817	, Q831	, Q845	, Q859	, Q873	, Q887	, Q901	, Q915	, Q929	, Q943	, Q957	, Q971	, Q985	, Q999	, Q1013	, Q1027	, Q1041	, Q1055	, Q1069	, Q1083	, Q1097	, Q1111	, Q1125	, Q1139	, Q1153	, Q1167	, Q1181	, Q1195	, Q1209	, Q1223	, Q1237	, Q1251	, Q1265	, Q1279	, Q1293	, Q1307	, Q1321	, Q1335	, Q1349	, Q1363
) as N_obs
from ppp.MFP
where ( Q3	, Q19	, Q33	, Q47	, Q61	, Q75	, Q89	, Q103	, Q117	, Q131	, Q145	, Q159	, Q173	, Q187	, Q201	, Q215	, Q229	, Q243	, Q257	, Q271	, Q285	, Q299	, Q313	, Q327	, Q341	, Q355	, Q369	, Q383	, Q397	, Q411	, Q425	, Q439	, Q453	, Q467	, Q481	, Q495	, Q509	, Q523	, Q537	, Q551	, Q565	, Q579	, Q593	, Q607	, Q621	, Q635	, Q649	, Q663	, Q677	, Q691	, Q705	, Q719	, Q733	, Q747	, Q761	, Q775	, Q789	, Q803	, Q817	, Q831	, Q845	, Q859	, Q873	, Q887	, Q901	, Q915	, Q929	, Q943	, Q957	, Q971	, Q985	, Q999	, Q1013	, Q1027	, Q1041	, Q1055	, Q1069	, Q1083	, Q1097	, Q1111	, Q1125	, Q1139	, Q1153	, Q1167	, Q1181	, Q1195	, Q1209	, Q1223	, Q1237	, Q1251	, Q1265	, Q1279	, Q1293	, Q1307	, Q1321	, Q1335	, Q1349	, Q1363
) &amp;gt;800;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am missing a key concept here, but I think it is close.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687723#M208815</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-09-30T05:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687724#M208816</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope I'm not missing something, but this seems like a case that practically cries out for an Array.&amp;nbsp; Something along the lines of (untested) the below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outdata;
    set ppp.MFP;
    ARRAY Days [*] Q1 - Q1363;
    Days_Calorie = 0;
    DO i = 1 TO DIM(Days);
        IF  Days[i] &amp;gt; 100  THEN
            Days_Calorie = Days_Calorie + 1;
    END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming each Q variable represents an observation for a separate day, the above should give you the number of days above 100 calories.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 05:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687724#M208816</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-30T05:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687789#M208846</link>
      <description>&lt;P&gt;I tend to agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;that an array is the most obvious way to do it. Bur the way he defined the array is not very efficient. Using "Q1-Q1363" as the array definition will mean that all the (nonexistent) variables like Q1, Q2, Q4 up to Q1262 will be defined, making the code run a lot slower.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dataset has the Qx variables consecutive and in the order you refer to them, you can use "Q3--Q1363". If your Qx variables are the only ones having a name starting with Q, you can refer to them as "Q:".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one solution using the first definition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set ppp.MFP;
  Days_Calorie=0;
  array Qs(*) 8 Q3--Q1363;
  do _N_=1 to dim(Qs);
    Days_Calorie+Qs(_N_)&amp;gt;100;
    end;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your Qx variables are not nicely ordered, AND you have other variables starting with Q, you can also define the array as all the variables that start with Q and a non-zero digit:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array Qs(*) 8 Q1: Q2: Q3: Q4: Q5: Q6: Q7: Q8: Q9:;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do it with SQL, you can also use SQL to create the expression you want, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select cats(name,'&amp;gt;100') into :test_expr separated by ',' 
  from dictionary.columns 
  where libname='PPP' and memname='MFP' 
     and name like 'Q%';
  create table want as select
    *,
    sum(&amp;amp;test_expr) as Days_Calorie
   from ppp.MFP;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The TEST_EXPR macro expression can also be used in a data step in exactly the same way, and it may perform a little faster than the array method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 12:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687789#M208846</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-30T12:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687812#M208854</link>
      <description>Thank you for the thoughtful reply! I do agree than an array seems like a no-brainer- I wish I would have thought of it.&lt;BR /&gt;&lt;BR /&gt;If I do have the entire slew of variables between Q1 - Q1363, what is the best way to pull out those individual variables? After Q3, the numbers are +14. For instance, Q19 +14 = Q33 + 14 = Q47. Is there any easy way to get all of those into an array, or should I split the dataset to only include these variables for this analysis?</description>
      <pubDate>Wed, 30 Sep 2020 13:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687812#M208854</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2020-09-30T13:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687846#M208864</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for the thoughtful reply! I do agree than an array seems like a no-brainer- I wish I would have thought of it.&lt;BR /&gt;&lt;BR /&gt;If I do have the entire slew of variables between Q1 - Q1363, what is the best way to pull out those individual variables? After Q3, the numbers are +14. For instance, Q19 +14 = Q33 + 14 = Q47. Is there any easy way to get all of those into an array, or should I split the dataset to only include these variables for this analysis?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you know the interval and it is ALWAYS exactly 14 then the do loop could be iterated such as&lt;/P&gt;
&lt;P&gt;do i = 1 to dim(arrayname) by 14;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;stuff using the iterated "i" values&amp;gt;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;so leave all the variables in the array assuming they are all numeric.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 15:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687846#M208864</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-30T15:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687906#M208886</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for the thoughtful reply! I do agree than an array seems like a no-brainer- I wish I would have thought of it.&lt;BR /&gt;&lt;BR /&gt;If I do have the entire slew of variables between Q1 - Q1363, what is the best way to pull out those individual variables? After Q3, the numbers are +14. For instance, Q19 +14 = Q33 + 14 = Q47. Is there any easy way to get all of those into an array, or should I split the dataset to only include these variables for this analysis?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would suggest creating a macro to solve that. Something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro criteria;
  %local i;
  Q3&amp;gt;100%do i=19 %to 1363&amp;nbsp;%by&amp;nbsp;14;,Q&amp;amp;i&amp;gt;100%end;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- it just generates a comma-separated list of all the criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which you can use in a datastep&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set ppp.MFP;
  Days_Calorie=sum(%criteria);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc SQL;
  create table want as select
  *,
  sum(%criteria) as Days_Calorie
  from ppp.MFP;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro looks a bit messy because I put all the generated code on one line in order to avoid spurious blanks in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to do the array stuff instead (I actually think it performs slower, so I would go with the SUM function solution), you can define the array with a macro as well:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro array_vars;
  %local i;
  Q3%do i=19 %to 1363&amp;nbsp;%by&amp;nbsp;14; Q&amp;amp;i%end;
%mend;

data want;
  set ppp.MFP;
  array Qx(*) 8 %array_vars;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then the rest of the datastep code as before. But IMO, it just adds another level of complication.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 17:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/687906#M208886</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-30T17:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/688003#M208923</link>
      <description>&lt;P&gt;Good catch,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;.&amp;nbsp; I wasn't paying attention to the specific variable names.&amp;nbsp; Yes, it would not be efficient to define a lot of non-existent variables.&amp;nbsp; And, yes, assuming that the variables are contiguous within the PDV, one could change the code as follows which would be far more efficient and avoids having to increment by 14.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data outdata;
    set ppp.MFP;
    ARRAY Days [*] Q1 -- Q1363;
    Days_Calorie = 0;
    DO i = 1 TO DIM(Days);
        IF  Days[i] &amp;gt; 100  THEN
            Days_Calorie = Days_Calorie + 1;
    END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It would be interesting to see if the SQL method that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;mentions is consistently faster than using an array (and whether it makes a material difference).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 20:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/688003#M208923</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-30T20:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/688126#M208988</link>
      <description>&lt;P&gt;Your data structure causes this to be an unnecessarily complicated process; a long layout makes this a breeze:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let treshold=100;

data mfp_long;
input id $ q $ val;
datalines;
A Q1 120
A Q19 95
A Q33 125
;

proc sql;
create table want as
  select
    id,
    count(*) as count
  from mfp_long
  where val &amp;gt; &amp;amp;treshold.
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See Maxim 19.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 07:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/688126#M208988</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-01T07:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count how many times an observation passes a threshold across variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/688439#M209129</link>
      <description>&lt;P&gt;And if you want to make sure that id's with no value above treshold are also shown, do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select
    id,
    sum(case
      when val &amp;gt; &amp;amp;treshold.
      then 1
      else 0
    end) as count
  from mfp_long
  group by id
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Oct 2020 07:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-how-many-times-an-observation-passes-a-threshold-across/m-p/688439#M209129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-02T07:37:16Z</dc:date>
    </item>
  </channel>
</rss>

