<?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 create new string column with sub-strings exits in existing string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789447#M252623</link>
    <description>&lt;P&gt;HELLO&lt;/P&gt;
&lt;P&gt;I have a long string field.&lt;/P&gt;
&lt;P&gt;I want to check check if 10 strings exits in the string field and create a new field that will contain the string values that contain .&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;For example:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If the long string value is "London is a nice city and I like Ice cream and I wish summer come soon"&lt;/P&gt;
&lt;P&gt;and I check the following sub-strings exits in long string:&lt;/P&gt;
&lt;P&gt;London,USA,summer ,New York, football,basketball,winter,Berlin,Autumn,food&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then in the new field I should get : "London,summer"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jan 2022 12:34:18 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2022-01-11T12:34:18Z</dc:date>
    <item>
      <title>create new string column with sub-strings exits in existing string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789447#M252623</link>
      <description>&lt;P&gt;HELLO&lt;/P&gt;
&lt;P&gt;I have a long string field.&lt;/P&gt;
&lt;P&gt;I want to check check if 10 strings exits in the string field and create a new field that will contain the string values that contain .&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;For example:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If the long string value is "London is a nice city and I like Ice cream and I wish summer come soon"&lt;/P&gt;
&lt;P&gt;and I check the following sub-strings exits in long string:&lt;/P&gt;
&lt;P&gt;London,USA,summer ,New York, football,basketball,winter,Berlin,Autumn,food&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then in the new field I should get : "London,summer"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 12:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789447#M252623</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2022-01-11T12:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: create new string column with sub-strings exits in existing string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789489#M252635</link>
      <description>&lt;P&gt;Array for the variables with the indicators and Index, Indexw, Find or Findw functions.&lt;/P&gt;
&lt;P&gt;If the list of values to search for is the same for all the records then likely a temporary array holding them would be a good idea. If they change you have a much more complicated problem and need actual data.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 15:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789489#M252635</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-11T15:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: create new string column with sub-strings exits in existing string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789533#M252646</link>
      <description>&lt;P&gt;I don't know if this would do the trick, but I coded a simple example that might extend to your case.Essentially, you need a do loop that can scan your string once for each substring you are looking to extract. In the end, the final x-sub-n variable will be the one you keep.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
infile datalines dsd;
input x  : $100.  ;
cards;
Shall I compare thee to a summer day in Boston?
;
run;
data want;
  set have;
  do i = 1 to 4;
  if index(x, 'Boston') then x1 = 'Boston'; else x1 = '';
  if index(x, 'compare') then x2 = catx(', ', 'compare', x1); else x2 = x1;
  if index(x, 'practice') then x3 = catx(', ', 'practice', x2); else x3 = x2;
    if index(x,'day') then x4 = catx(', ', 'day', x3); else x4 = x3;
  end;
  run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jan 2022 16:36:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789533#M252646</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2022-01-11T16:36:42Z</dc:date>
    </item>
    <item>
      <title>Re: create new string column with sub-strings exits in existing string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789541#M252651</link>
      <description>&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/n1obc9u7z3225mn1npwnassehff0.htm" target="_self"&gt;CALL PRXNEXT&lt;/A&gt; Function, just modify the example slightly and you get this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;
	length result $100 ; /* result variable */
	string="London is a nice city and I like Ice cream and I wish summer come soon" ; /* String to search */
	searchTerms="/London|USA|summer|New York|football|basketball|winter|Berlin|Autumn|food/" ; /* Search terms */
	searchPattern=prxparse(searchTerms); /* Creates the pattern Id for the search terms */
	start=1 ; /* Position to start search from */
	stop=length(string) ; /* Position to end search */
	call prxnext(searchPattern, start, stop, string, position, length); /* Search for the first occurance of a term in the string, return the position and lenght of the found term */
	result="" ; /* initialize result to blank */
	flag=0 ; /* flag for commas in the result */
 	do while (position &amp;gt; 0); /* loop while we find matches */
		found = substr(string, position, length); /* What did we find */
		put found= position= length=;
		if flag=1 then /* Build the result variable */
			result=trim(result)||","||found ;			
		else
			result=trim(result)||found ;			
		call prxnext(searchPattern, start, stop, string, position, length); /* search for the next occurance of a term */
		flag=1 ;
	end;
	put result= ; /* write result to log */
run ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jan 2022 17:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789541#M252651</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-01-11T17:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: create new string column with sub-strings exits in existing string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789696#M252750</link>
      <description>&lt;PRE&gt;data have;
infile datalines dsd;
input x  : $100.  ;
cards;
London is a nice city and I like Ice cream and I wish summer come soon
Shall I compare thee to a summer day in Boston?
;
run;


%let keys= London,USA,summer ,New York, football,basketball,winter,Berlin,Autumn,food  ;
data want;
 set have;
 length want $200. ;
 do i=1 to countw("&amp;amp;keys.",',');
  temp=scan("&amp;amp;keys.",i,',');
  if findw(x,temp,,'itsp') then want=catx(',',want,temp);
 end;
 drop i temp;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jan 2022 13:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-new-string-column-with-sub-strings-exits-in-existing/m-p/789696#M252750</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-12T13:07:07Z</dc:date>
    </item>
  </channel>
</rss>

