<?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 remove a fixed string from the text? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/689077#M209451</link>
    <description>&lt;P&gt;No, this isn't a replacement; this is a concatenation.&amp;nbsp; The CATX function is concatenating the strings together separated by a comma.&amp;nbsp; With CATX, the first argument specifies the separator.&amp;nbsp; The slash is your end of record delimiter, but a comma separates each "token" in your records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program first determines how many string tokens there are by counting the comma separators (and adding one since there is no comma after the final string token).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_Strings					=	COUNT(Comments, ',')	+	1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the program goes through the tokens, one at a time.&amp;nbsp; Each token will be concatenated into the output record&amp;nbsp;&lt;STRONG&gt;unless&lt;/STRONG&gt; the token contains&amp;nbsp;'UGESTAGE' in which case it will be skipped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	DO	_i						=	1	TO	_Strings;
		IF	NOT	INDEX(SCAN(Comments, _i), 'UGESTAGE')	THEN
			DO;
				Output_Comment	=	CATX(', ', STRIP(Output_Comment), STRIP(SCAN(Comments, _i, ',')));
			END;
	END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Tue, 06 Oct 2020 04:20:05 GMT</pubDate>
    <dc:creator>jimbarbour</dc:creator>
    <dc:date>2020-10-06T04:20:05Z</dc:date>
    <item>
      <title>How to remove a fixed string from the text?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688632#M209226</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to remove all the strings which contains 'UGESTAGE' in the sample dataset 'Have.'&amp;nbsp;&amp;nbsp;&amp;nbsp; I am looking for the result like the dataset 'Want.'&amp;nbsp;&amp;nbsp; Please help me to approach it, thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data Have;
      infile datalines delimiter='#';
  input Comments : $200.  ;
datalines;
	UGESTAGE=34 5/7 WKS #
	CHOLESTASIS,     UGESTAGE = 35WKS,  ANEMIA#
	UGESTAGE=33.4 WKS , ROP #
	ASD, UGESTAGE= 24WKS
;
run;

data Want;
      infile datalines delimiter='/';
  input Disease : $300.  ;
datalines;
	/ /
	CHOLESTASIS, ANEMIA /
	ROP /
	/ASD /
;
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Oct 2020 23:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688632#M209226</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-10-02T23:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a fixed string from the text?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688634#M209227</link>
      <description>&lt;P&gt;The SCAN function should come in handy in this case; code example, below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really want to keep the record if all strings are removed?&amp;nbsp; I deleted it, but the code can be easily modified to output the record even if all of the contents have been deleted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I didn't include it in the below SAS code, but of course if your data is anything but upper case, you would need to use lowcase() or upcase() to make sure that the comparison is case insensitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
      infile datalines delimiter='#';
  input Comments : $200.  ;
datalines;
	UGESTAGE=34 5/7 WKS #
	CHOLESTASIS,     UGESTAGE = 35WKS,  ANEMIA#
	UGESTAGE=33.4 WKS , ROP #
	ASD, UGESTAGE= 24WKS
;
run;

Data	Want(RENAME=(Output_Comment=Comments));
	DROP	_:;
	DROP	Comments;
	LENGTH	Output_Comment	$256;
	SET	Have;
	_Strings					=	COUNT(Comments, ',')	+	1;

	DO	_i						=	1	TO	_Strings;
		IF	NOT	INDEX(SCAN(Comments, _i), 'UGESTAGE')	THEN
			DO;
				Output_Comment	=	CATX(', ', STRIP(Output_Comment), STRIP(SCAN(Comments, _i, ',')));
			END;
	END;

	IF	LENGTHN(Output_Comment)	=	0	THEN
		DELETE;
	ELSE
		Output_Comment			=	CAT(STRIP(Output_Comment), ' /');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601681120823.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50141i4529AC22AE1E308B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601681120823.png" alt="jimbarbour_0-1601681120823.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 23:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688634#M209227</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-02T23:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a fixed string from the text?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688691#M209269</link>
      <description>In your result, the first row is missing.   It should be blank for the first obs.</description>
      <pubDate>Sat, 03 Oct 2020 14:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688691#M209269</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-10-03T14:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a fixed string from the text?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688697#M209273</link>
      <description>&lt;P&gt;Yes, it was deleted.&amp;nbsp; See my comments in my first response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you really need it?&amp;nbsp; No problem.&amp;nbsp; Just comment out the DELETE logic like the below.&amp;nbsp; See results below that.&amp;nbsp; How does that look?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data	Want(RENAME=(Output_Comment=Comments));
	DROP	_:;
	DROP	Comments;
	LENGTH	Output_Comment	$256;
	SET	Have;
	_Strings					=	COUNT(Comments, ',')	+	1;

	DO	_i						=	1	TO	_Strings;
		IF	NOT	INDEX(SCAN(Comments, _i), 'UGESTAGE')	THEN
			DO;
				Output_Comment	=	CATX(', ', STRIP(Output_Comment), STRIP(SCAN(Comments, _i, ',')));
			END;
	END;

/*	IF	LENGTHN(Output_Comment)	=	0	THEN*/
/*		DELETE;*/
/*	ELSE*/
		Output_Comment			=	CAT(STRIP(Output_Comment), ' /');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1601737741808.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50150i566C79A7BBA43770/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1601737741808.png" alt="jimbarbour_0-1601737741808.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Oct 2020 15:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688697#M209273</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-03T15:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a fixed string from the text?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688999#M209413</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your codes below, is the &lt;SPAN class="token function keyword"&gt;STRIP&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Output_Comment&lt;SPAN class="token punctuation"&gt;) used to replace the '&amp;nbsp;&lt;SPAN class="token function keyword"&gt;STRIP&lt;/SPAN&gt;(&lt;SPAN class="token function keyword"&gt;SCAN&lt;/SPAN&gt;(Comments, _i, &lt;SPAN class="token string"&gt;','&lt;/SPAN&gt;))'? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token function keyword"&gt;CATX&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;', '&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function keyword"&gt;STRIP&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Output_Comment&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token function keyword"&gt;STRIP&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function keyword"&gt;SCAN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Comments&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; _i&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;','&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 20:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/688999#M209413</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-10-05T20:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a fixed string from the text?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/689077#M209451</link>
      <description>&lt;P&gt;No, this isn't a replacement; this is a concatenation.&amp;nbsp; The CATX function is concatenating the strings together separated by a comma.&amp;nbsp; With CATX, the first argument specifies the separator.&amp;nbsp; The slash is your end of record delimiter, but a comma separates each "token" in your records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The program first determines how many string tokens there are by counting the comma separators (and adding one since there is no comma after the final string token).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_Strings					=	COUNT(Comments, ',')	+	1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the program goes through the tokens, one at a time.&amp;nbsp; Each token will be concatenated into the output record&amp;nbsp;&lt;STRONG&gt;unless&lt;/STRONG&gt; the token contains&amp;nbsp;'UGESTAGE' in which case it will be skipped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	DO	_i						=	1	TO	_Strings;
		IF	NOT	INDEX(SCAN(Comments, _i), 'UGESTAGE')	THEN
			DO;
				Output_Comment	=	CATX(', ', STRIP(Output_Comment), STRIP(SCAN(Comments, _i, ',')));
			END;
	END;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 04:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-fixed-string-from-the-text/m-p/689077#M209451</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-06T04:20:05Z</dc:date>
    </item>
  </channel>
</rss>

