<?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: String of binary varaibles to a new varaible with count in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833041#M35749</link>
    <description>&lt;P&gt;Binary really should be numeric as the summary functions are ever so useful.&lt;/P&gt;
&lt;P&gt;If your S1 to S6 are numeric then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sum(of s1-s6) = Number of 1s&lt;/P&gt;
&lt;P&gt;n(of s1-s6) - sum(of s1-s6) = Number of zeros&lt;/P&gt;
&lt;P&gt;n(of s1-s6) = number of responses&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You character version also loses information for any observation where not all of the 6 variables were populated. Quick if you see "1011" which 4 of the 6 had a response? You get the same result for S1=1 S2=0 S3=1 and S4=1 as for S1=1 S2=missing S3=0 S4=1 and S5=1,&lt;/P&gt;
&lt;P&gt;S1=1 S2=missing S3 = missing S4=0 S5=1 and S6=1 and a few more combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your s1 to s6 are numeric then you likely had problems with what catx does with the conversion to character as without some additional control you would have blanks in the converted values.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Sep 2022 04:23:49 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-09-13T04:23:49Z</dc:date>
    <item>
      <title>String of binary varaibles to a new varaible with count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833025#M35744</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a wide format dataset and then each ID has 6 columns from different surveys (i.e., each variable are binary and simply indicate whether the participants responded to that survey, 0= not responded and 1=responded) . I am creating some descriptive stats to understand how many people had 1 survey missing and how many people had 2 survey missing and so on (or the other way round as how many people had responded certain number of surveys). So what I have done was first creating a string variable so that I have a pattern of the response for each participant like before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data response_finalsample_;
	SET  response_finalsample_;
	length responsex $ 6;
	responsex = cat (of s1-s6);
RUN;&lt;/PRE&gt;&lt;P&gt;The above is successful as I can see I've created a new column showing the string of the response like "110101" "000011" etc&lt;/P&gt;&lt;P&gt;But the problem arises as I would like to create a new variable so that it shows how many '0' or '1' in the string variable as above.&lt;/P&gt;&lt;P&gt;I thought I could use count function but it does not work because the new created variable did not match the actual number of responses of a participant.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA response_finalsample_;
	count_miss = countc(responsex, '1');
	output;
RUN;&lt;/PRE&gt;&lt;P&gt;It would be really helpful if someone could point the direction of doing this.&lt;BR /&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 00:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833025#M35744</guid>
      <dc:creator>VKWS</dc:creator>
      <dc:date>2022-09-13T00:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: String of binary varaibles to a new varaible with count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833040#M35748</link>
      <description>&lt;P&gt;One way is to remove all the 1 (or zeros) from the string and then determine the length of the remaining string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile datalines truncover;
  input var $10.;
  n0=lengthn(compress(var,'0 '));
  n1=lengthn(compress(var,'1 '));
  datalines;
00001010
01010010
010
 
000  00
;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1663041680703.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75168i69693B8860E022A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1663041680703.png" alt="Patrick_0-1663041680703.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 04:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833040#M35748</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-09-13T04:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: String of binary varaibles to a new varaible with count</title>
      <link>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833041#M35749</link>
      <description>&lt;P&gt;Binary really should be numeric as the summary functions are ever so useful.&lt;/P&gt;
&lt;P&gt;If your S1 to S6 are numeric then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sum(of s1-s6) = Number of 1s&lt;/P&gt;
&lt;P&gt;n(of s1-s6) - sum(of s1-s6) = Number of zeros&lt;/P&gt;
&lt;P&gt;n(of s1-s6) = number of responses&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You character version also loses information for any observation where not all of the 6 variables were populated. Quick if you see "1011" which 4 of the 6 had a response? You get the same result for S1=1 S2=0 S3=1 and S4=1 as for S1=1 S2=missing S3=0 S4=1 and S5=1,&lt;/P&gt;
&lt;P&gt;S1=1 S2=missing S3 = missing S4=0 S5=1 and S6=1 and a few more combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your s1 to s6 are numeric then you likely had problems with what catx does with the conversion to character as without some additional control you would have blanks in the converted values.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2022 04:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/String-of-binary-varaibles-to-a-new-varaible-with-count/m-p/833041#M35749</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-13T04:23:49Z</dc:date>
    </item>
  </channel>
</rss>

