<?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: COMB or contains funtions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/349293#M80989</link>
    <description>&lt;P&gt;Just a small typo:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; N1 &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cat&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'B'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Apr 2017 23:39:09 GMT</pubDate>
    <dc:creator>ilikesas</dc:creator>
    <dc:date>2017-04-11T23:39:09Z</dc:date>
    <item>
      <title>COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263002#M51460</link>
      <description>&lt;P&gt;Hi!&amp;nbsp; I have a variable&amp;nbsp; with 30+ sequences that I need to now put into 3 categories.&amp;nbsp;&amp;nbsp; If the variable contains&amp;nbsp; &amp;gt;=4&amp;nbsp; of a 0 or 1 they are assigned value A and B respecitvely.&amp;nbsp; All others=C.&amp;nbsp; THe sequence combination is not relevant, just the number of a certain digit in the value.&amp;nbsp; I'm not sure which function i should use here. Help is appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;00000&amp;nbsp; * would be new_Value 'A';&lt;/P&gt;
&lt;P&gt;00001&amp;nbsp; * would be new_Value 'A';&lt;/P&gt;
&lt;P&gt;00010&amp;nbsp; * would be new_Value 'A';&lt;/P&gt;
&lt;P&gt;00011&amp;nbsp; * would be new_Value 'C';&lt;/P&gt;
&lt;P&gt;00100&amp;nbsp; * would be new_Value 'A';&lt;/P&gt;
&lt;P&gt;01000&amp;nbsp; * would be new_Value 'A';&lt;/P&gt;
&lt;P&gt;01100&amp;nbsp; * would be new_Value 'C';&lt;/P&gt;
&lt;P&gt;11000&amp;nbsp; * would be new_Value 'C';&lt;/P&gt;
&lt;P&gt;10111&amp;nbsp; * would be new_Value 'B;&lt;/P&gt;
&lt;P&gt;11110&amp;nbsp; * would be new_Value 'B';&lt;/P&gt;
&lt;P&gt;11111&amp;nbsp; * would be new_Value 'B';&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263002#M51460</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2016-04-11T20:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263012#M51462</link>
      <description>&lt;P&gt;Read each 0/1 into its own variable, then use the sum function. If the sum&amp;gt; X then assign A/B, otherwise C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263012#M51462</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T20:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263013#M51463</link>
      <description>Countc()</description>
      <pubDate>Mon, 11 Apr 2016 20:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263013#M51463</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-04-11T20:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263018#M51465</link>
      <description>&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input seq $; &lt;BR /&gt;datalines;&lt;BR /&gt;00000&lt;BR /&gt;00001&lt;BR /&gt;00010&lt;BR /&gt;00011&lt;BR /&gt;00100&lt;BR /&gt;01000&lt;BR /&gt;01100&lt;BR /&gt;11000&lt;BR /&gt;10111&lt;BR /&gt;11110&lt;BR /&gt;11111&lt;BR /&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;count_zero=0;&lt;BR /&gt;count_one=0;&lt;BR /&gt;category='C';&lt;BR /&gt;do i=1 to length(seq);&lt;BR /&gt;if substr(seq,i,1)='0' then count_zero+1;&lt;BR /&gt;if substr(seq,i,1)='1' then count_one+1;&lt;BR /&gt;end;&lt;BR /&gt;if count_zero&amp;gt;=4 then category='A';&lt;BR /&gt;if count_one&amp;gt;=4 then category='B';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263018#M51465</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2016-04-11T20:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263032#M51469</link>
      <description>&lt;P&gt;And just to go around the bend a bit, here is solution using a format. The data step builds a set to build the format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data junk;
   length start label $ 5;
   FMTNAME = 'MYCATEGORIES';
   type='C';
   do a=0,1;
   do b=0,1;
   do c=0,1;
   do d=0,1;
   do e=0,1;
      start=cats(a,b,c,d,e);
      sum=sum(a,b,c,d,e); 
      select (sum);
         when (0,1) Label='A';
         when (4,5) Label='B';
         otherwise Label='C';
      end;
      output;
   end;
   end;
   end;
   end;
   end;
run;

proc format LIBRARY=work cntlin=junk;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The you could possibly use the format instead of creating a new variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc freq data=have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Tables myvar;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Format myvar $mycategories. ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Or if you really want a variable&lt;/P&gt;
&lt;P&gt;Newvar = put(myvar, $mycategories.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This wouldn't be the easiest solution BUT does have the potential of allowing an "other" clause added to the junk data set to address things like the value being '0100'. What if the variable doesn't have all 5 columns? What do you want to assign? Or possibly even more interesting a value of '01 00'? You could add one line to the junk dataset that would handle values that were too short, had other than 0 adn 1 characters and potentially too long by having a formatted value of blank or 'Z' or something else.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263032#M51469</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-11T20:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263043#M51475</link>
      <description>&lt;P&gt;Loop through is definitely not the most efficient...&lt;/P&gt;
&lt;P&gt;Here's the COUNTC example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
N1=countc(seq, '1');
N0=countc(seq, '0');


if N0 &amp;gt;= 4 then cat='A';
else if N0 &amp;gt;= 4 then cat='B';
else cat='C';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 22:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/263043#M51475</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T22:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: COMB or contains funtions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/349293#M80989</link>
      <description>&lt;P&gt;Just a small typo:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; N1 &lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;cat&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'B'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 23:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/COMB-or-contains-funtions/m-p/349293#M80989</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-04-11T23:39:09Z</dc:date>
    </item>
  </channel>
</rss>

