<?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 character variables that begins with... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-character-variables-that-begins-with/m-p/805840#M317448</link>
    <description>&lt;P&gt;This is UNTESTED code. If you want tested code, you must provide a portion of your data as SAS data step code which you can type in yourself or have SAS create it (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;); and not in any other format. This code uses the =: (note the colon after the equal sign) to test if a string &lt;EM&gt;begins with&lt;/EM&gt; a certain value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array y code_1-code_44;
    do i=1 to dim(y);
        count=sum(count,y(i)=:'T08');
    end;
run;
        &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Apr 2022 12:37:08 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-04-04T12:37:08Z</dc:date>
    <item>
      <title>count character variables that begins with...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-character-variables-that-begins-with/m-p/805836#M317447</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want a variable "T08_count" that counts the 6 character long variables "code_1-code_44", which BEGIN with "T08". I have made following code, but then it count all variables of&amp;nbsp;"code_1-code_44" which contain "T08" at any place in the string:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data pb;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set work.pb;&lt;/P&gt;&lt;P&gt;array t (1) $6_temporary_('T08');&lt;/P&gt;&lt;P&gt;do i=1 to dim(t);&lt;/P&gt;&lt;P&gt;T08_count=sum(T08_count, count(catx(' ', of code_1-code_44), STRIP( t[i], 'i'));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 12:00:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-character-variables-that-begins-with/m-p/805836#M317447</guid>
      <dc:creator>mwei0041</dc:creator>
      <dc:date>2022-04-04T12:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: count character variables that begins with...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-character-variables-that-begins-with/m-p/805840#M317448</link>
      <description>&lt;P&gt;This is UNTESTED code. If you want tested code, you must provide a portion of your data as SAS data step code which you can type in yourself or have SAS create it (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;); and not in any other format. This code uses the =: (note the colon after the equal sign) to test if a string &lt;EM&gt;begins with&lt;/EM&gt; a certain value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array y code_1-code_44;
    do i=1 to dim(y);
        count=sum(count,y(i)=:'T08');
    end;
run;
        &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 12:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-character-variables-that-begins-with/m-p/805840#M317448</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-04T12:37:08Z</dc:date>
    </item>
  </channel>
</rss>

