<?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: Count of any two of three variables having similar responses in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25413#M5764</link>
    <description>a sas9 feature (not sure if it is available earlier) which seems to be most appropriate is the count() function.&lt;BR /&gt;
It works on strings, but the catx() function provides a flexible way of collecting variables into a string with delimiters ensuring the original columns can still be distinguished.&lt;BR /&gt;
Demonstrated here in a ~"flexible" kind of way with a mixture of data-type columns[pre]106  %let var_list = age name height ;&lt;BR /&gt;
107  data;&lt;BR /&gt;
108   set sashelp.class ;&lt;BR /&gt;
109&lt;BR /&gt;
110   ** alter content to prove the counting works ;&lt;BR /&gt;
111   if _n_ in( 1,5,9) then name='1' ;&lt;BR /&gt;
112   if _n_ in( 3,5,8) then height=1 ;&lt;BR /&gt;
113&lt;BR /&gt;
114   ones_ct = count( '||' !! catx( '||', of &amp;amp;var_list ) !!'||', '|1|' ) ;&lt;BR /&gt;
115  run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.DATA13 has 19 observations and 6 variables.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
It places two pipe(|) marks around and between column values and searches for single pipes surrounding each 1. There might be a simpler way to maintain separation of the ones, but I found a problem with a single pipe when consecutive variable have value=1.&lt;BR /&gt;
&lt;BR /&gt;
For Mirisage's data:&lt;BR /&gt;
 change the variable names assigned to the macro variable &amp;amp;var_list&lt;BR /&gt;
 replace sashelp.class with the appropriate dataset and &lt;BR /&gt;
remove the testing lines numbered 110 to 112 in the log above.&lt;BR /&gt;
 &lt;BR /&gt;
  &lt;BR /&gt;
PeterC</description>
    <pubDate>Thu, 27 May 2010 08:19:30 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2010-05-27T08:19:30Z</dc:date>
    <item>
      <title>Count of any two of three variables having similar responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25410#M5761</link>
      <description>Hi Colleagues,&lt;BR /&gt;
&lt;BR /&gt;
Could anyone help me to write a SAS code for the following real life problem?&lt;BR /&gt;
&lt;BR /&gt;
My simplified data set is like this.&lt;BR /&gt;
&lt;BR /&gt;
Data food;&lt;BR /&gt;
Input Household Q2 Q06 Q14;&lt;BR /&gt;
Cards;&lt;BR /&gt;
&lt;BR /&gt;
1 1	1	9&lt;BR /&gt;
2 2	2	2&lt;BR /&gt;
3 6	6	6&lt;BR /&gt;
4 1	7	1&lt;BR /&gt;
5 7	1	1&lt;BR /&gt;
6 6	1	6&lt;BR /&gt;
7 1	1	2&lt;BR /&gt;
8 2	9	2&lt;BR /&gt;
;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I need to take the count of households where a household gets two responses of 1 s for any of the two variables.&lt;BR /&gt;
&lt;BR /&gt;
For example, answer for this data set is 4 because 4 HHs have two responses of 1 s across three variables.&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Neil</description>
      <pubDate>Thu, 20 May 2010 21:45:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25410#M5761</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-05-20T21:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count of any two of three variables having similar responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25411#M5762</link>
      <description>The following code fragments will create a dichotomous 0 or 1 for the condition, depending on whether you are concerned about exactly 2 or 2 or more are ones.&lt;BR /&gt;
&lt;BR /&gt;
Proc means and sum on the variable of choice will give you the count.&lt;BR /&gt;
&lt;BR /&gt;
Exactly two ones:&lt;BR /&gt;
&lt;BR /&gt;
two_ones= (sum((q2=1),(q06=1),(q14=1)) =2);&lt;BR /&gt;
&lt;BR /&gt;
Two or more ones:&lt;BR /&gt;
two_or_more_ones= (sum((q2=1),(q06=1),(q14=1)) ge 2);&lt;BR /&gt;
&lt;BR /&gt;
This will also handling missing values.</description>
      <pubDate>Thu, 20 May 2010 22:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25411#M5762</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2010-05-20T22:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count of any two of three variables having similar responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25412#M5763</link>
      <description>Hi ballardw,&lt;BR /&gt;
&lt;BR /&gt;
Your codes worked marvelously! They are great!&lt;BR /&gt;
&lt;BR /&gt;
Thank you so munch.&lt;BR /&gt;
&lt;BR /&gt;
Mirisage</description>
      <pubDate>Fri, 21 May 2010 14:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25412#M5763</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2010-05-21T14:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count of any two of three variables having similar responses</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25413#M5764</link>
      <description>a sas9 feature (not sure if it is available earlier) which seems to be most appropriate is the count() function.&lt;BR /&gt;
It works on strings, but the catx() function provides a flexible way of collecting variables into a string with delimiters ensuring the original columns can still be distinguished.&lt;BR /&gt;
Demonstrated here in a ~"flexible" kind of way with a mixture of data-type columns[pre]106  %let var_list = age name height ;&lt;BR /&gt;
107  data;&lt;BR /&gt;
108   set sashelp.class ;&lt;BR /&gt;
109&lt;BR /&gt;
110   ** alter content to prove the counting works ;&lt;BR /&gt;
111   if _n_ in( 1,5,9) then name='1' ;&lt;BR /&gt;
112   if _n_ in( 3,5,8) then height=1 ;&lt;BR /&gt;
113&lt;BR /&gt;
114   ones_ct = count( '||' !! catx( '||', of &amp;amp;var_list ) !!'||', '|1|' ) ;&lt;BR /&gt;
115  run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
NOTE: The data set WORK.DATA13 has 19 observations and 6 variables.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
It places two pipe(|) marks around and between column values and searches for single pipes surrounding each 1. There might be a simpler way to maintain separation of the ones, but I found a problem with a single pipe when consecutive variable have value=1.&lt;BR /&gt;
&lt;BR /&gt;
For Mirisage's data:&lt;BR /&gt;
 change the variable names assigned to the macro variable &amp;amp;var_list&lt;BR /&gt;
 replace sashelp.class with the appropriate dataset and &lt;BR /&gt;
remove the testing lines numbered 110 to 112 in the log above.&lt;BR /&gt;
 &lt;BR /&gt;
  &lt;BR /&gt;
PeterC</description>
      <pubDate>Thu, 27 May 2010 08:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-of-any-two-of-three-variables-having-similar-responses/m-p/25413#M5764</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-05-27T08:19:30Z</dc:date>
    </item>
  </channel>
</rss>

