<?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: How to subgroup based on the _ criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628343#M185649</link>
    <description>&lt;P&gt;I'm feeling generous. Here's one example of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s suggestion.&lt;/P&gt;
&lt;P&gt;Note that I am only reading your Name variable.&lt;/P&gt;
&lt;PRE&gt;data datain1;
      infile datalines dsd;
  input Name : $300.  ;
  array result (3) $100;
  do i=1 to countw(name,'_');
   result[i] = scan(name,i,'_');
  end;
  drop i;
datalines;
	5648_6666, 5648, 6666,
	000_9463, 000, 9463,
	000_4721_444, 000, 4721, 444
	4721_00_999, 4721, 00, 999
;
run;
&lt;/PRE&gt;
&lt;P&gt;Caveat: To create the Array you really need to know the maximum number of values you might encounter. If you declare the array for 3 as in the example and one of the name values was 12_34_56_78 then Countw will return 4 words and attempt to loop to the 4th element of the result array. Which was not defined, only 3.&lt;/P&gt;
&lt;P&gt;Also consecutive _ may not do exactly what you want. Test it and see with a value like 123__456 (that is two consecutive underscores). Another case to consider is behavior if the first or last character is an _.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Feb 2020 21:01:45 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-02-28T21:01:45Z</dc:date>
    <item>
      <title>How to subgroup based on the _ criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628325#M185636</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to get the seperated subgroups Result1-Result3 from the column 'Name' when the numbers are separated by _.&amp;nbsp;&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data datain1;
      infile datalines dsd;
  input Name : $300.  Result1 : $100. Result2 : $100. Result3 : $100.;
datalines;
	5648_6666, 5648, 6666,
	000_9463, 000, 9463,
	000_4721_444, 000, 4721, 444
	4721_00_999, 4721, 00, 999
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Feb 2020 20:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628325#M185636</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-28T20:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to subgroup based on the _ criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628326#M185637</link>
      <description>&lt;P&gt;You can use the SCAN() function along with the COUNTW() function, with the underscore as the delimiter, in a loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 20:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628326#M185637</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-28T20:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to subgroup based on the _ criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628343#M185649</link>
      <description>&lt;P&gt;I'm feeling generous. Here's one example of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s suggestion.&lt;/P&gt;
&lt;P&gt;Note that I am only reading your Name variable.&lt;/P&gt;
&lt;PRE&gt;data datain1;
      infile datalines dsd;
  input Name : $300.  ;
  array result (3) $100;
  do i=1 to countw(name,'_');
   result[i] = scan(name,i,'_');
  end;
  drop i;
datalines;
	5648_6666, 5648, 6666,
	000_9463, 000, 9463,
	000_4721_444, 000, 4721, 444
	4721_00_999, 4721, 00, 999
;
run;
&lt;/PRE&gt;
&lt;P&gt;Caveat: To create the Array you really need to know the maximum number of values you might encounter. If you declare the array for 3 as in the example and one of the name values was 12_34_56_78 then Countw will return 4 words and attempt to loop to the 4th element of the result array. Which was not defined, only 3.&lt;/P&gt;
&lt;P&gt;Also consecutive _ may not do exactly what you want. Test it and see with a value like 123__456 (that is two consecutive underscores). Another case to consider is behavior if the first or last character is an _.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 21:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628343#M185649</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-28T21:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to subgroup based on the _ criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628346#M185651</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;To create the Array you really need to know the maximum number of values you might encounter.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That sounds like &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 3&lt;/A&gt;!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 21:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-subgroup-based-on-the-criteria/m-p/628346#M185651</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-28T21:06:14Z</dc:date>
    </item>
  </channel>
</rss>

