<?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: Search for character in a list and remove it in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873211#M345007</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, the transtrn as coded will remove '4,', but it did not remove the trailing '4' (as in '0,4') in the first observation.&amp;nbsp; &amp;nbsp;And it would also change '0,14,'16' to '0,116'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited note:&lt;/P&gt;
&lt;P&gt;Earlier, there was a suggestion, now deleted, of using the TRANSTRN function, which prompted my response above.&amp;nbsp; Here is a way that TRANSTRN can be used without the problems I mentioned.&amp;nbsp; It requires prepending and appending a ',' to days_missing, then run TRANSTRN against individual values, also preceded and succeeded by commas.&amp;nbsp; Finally remove the extra commas:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length new_days_missing $42;
  new_days_missing=cats(',',days_missing,',');

  if form='exam' then do;
    if findw(days,'3',',') then new_days_missing=transtrn(new_days_missing,',4,',',');
    if findw(days,'1',',') then new_days_missing=transtrn(new_days_missing,',0,',',');
  end;
  else if form='lab' then do;
    if findw(days,'1',',') then new_days_missing=transtrn(new_days_missing,',0,',',');
  end;
  if new_days_missing=',' then new_days_missing=' ';
  else new_days_missing=substr(new_days_missing,2,length(new_days_missing)-2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2023 22:20:11 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-05-01T22:20:11Z</dc:date>
    <item>
      <title>Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873191#M345001</link>
      <description>&lt;P&gt;Hello, I need to remove characters from a string based on multiple conditions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data I have looks like this:&lt;/P&gt;&lt;P&gt;Animal&amp;nbsp; &amp;nbsp; &amp;nbsp;Form&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Days&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Days_Expected&amp;nbsp; &amp;nbsp; Days_Missing&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,36,103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,1,2,4,36,103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,4&amp;nbsp;&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lab&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,36,100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,1,2,4,30,100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,4,30&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need a function that will remove characters from the missing value based on criteria in the days value.&lt;/P&gt;&lt;P&gt;For instance, If form=exam and days contains '3', then remove '4' from days_missing and if&amp;nbsp;form=exam and days contains '1', then remove '0' from days missing.&amp;nbsp; Also, if form=lab and days contains '1' then remove '0' from days_missing&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The outcome wanted would be this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Animal&amp;nbsp; &amp;nbsp; &amp;nbsp;Form&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Days&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Days_Expected&amp;nbsp; &amp;nbsp; Days_Missing&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,36,103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,1,2,4,36,103&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lab&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1,2,3,36,100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0,1,2,4,30,100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4,30&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 15:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873191#M345001</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-05-01T15:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873198#M345005</link>
      <description>&lt;P&gt;Is that ALL of the rules? Are there other values for "Form" that are going to have conditions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think that you want to carefully restate your conditions and what is removed. If you remove '0' then '103' becomes '13' if it made it into the "days missing". Similarly the '30' would become '3'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And show the code you are actually using to identify the "days-missing" as it may be better to apply the filters before adding the value to 'days_missing' to begin with. As apparently they are not missing and not supposed to be missing.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 15:34:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873198#M345005</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-01T15:34:52Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873203#M345006</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length animal $4 form $4 days $40 days_expected $40 days_missing $40;
   animal='1001';
   form='exam';
   days='1,2,3,36,103';
   days_expected='0,1,2,4,36,103';
   days_missing='0,4';
   output;
   animal='1001';
   form='lab';
   days='1,2,3,36,100';
   days_expected='0,1,2,4,30,100';
   days_missing='0,4,30';
   output;
proc print;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 16:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873203#M345006</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-05-01T16:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873211#M345007</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, the transtrn as coded will remove '4,', but it did not remove the trailing '4' (as in '0,4') in the first observation.&amp;nbsp; &amp;nbsp;And it would also change '0,14,'16' to '0,116'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited note:&lt;/P&gt;
&lt;P&gt;Earlier, there was a suggestion, now deleted, of using the TRANSTRN function, which prompted my response above.&amp;nbsp; Here is a way that TRANSTRN can be used without the problems I mentioned.&amp;nbsp; It requires prepending and appending a ',' to days_missing, then run TRANSTRN against individual values, also preceded and succeeded by commas.&amp;nbsp; Finally remove the extra commas:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length new_days_missing $42;
  new_days_missing=cats(',',days_missing,',');

  if form='exam' then do;
    if findw(days,'3',',') then new_days_missing=transtrn(new_days_missing,',4,',',');
    if findw(days,'1',',') then new_days_missing=transtrn(new_days_missing,',0,',',');
  end;
  else if form='lab' then do;
    if findw(days,'1',',') then new_days_missing=transtrn(new_days_missing,',0,',',');
  end;
  if new_days_missing=',' then new_days_missing=' ';
  else new_days_missing=substr(new_days_missing,2,length(new_days_missing)-2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 22:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873211#M345007</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-01T22:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873214#M345008</link>
      <description>&lt;P&gt;do you have a better solution?&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 16:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873214#M345008</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-05-01T16:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873216#M345009</link>
      <description>&lt;P&gt;I saw your other post about how to generate days_missing.&amp;nbsp; I think you are making life VERY hard for yourself by designing a data structure with these comma separated lists stored in character variables.&amp;nbsp; Typically things are easier if you work with a vertical structure.&amp;nbsp; I don't quite understand your data, but it looks like maybe you are keeping track of forms that are due (expected), and whether or not they have been received.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of structuring like:&lt;/P&gt;
&lt;PRE&gt;Animal     Form        Days                     Days_Expected    Days_Missing
1001        exam        1,2,3,36,103        0,1,2,4,36,103          0,4 
1001        lab         1,2,3,36,100        0,1,2,4,30,100          0,4,30 
&lt;/PRE&gt;
&lt;P&gt;You could structure to have one record per form that is expected, with a boolean variable to indicate whether or not the form was received e.g.:&lt;/P&gt;
&lt;PRE&gt;Animal  Form  Day  Received
1001    exam  0    0
1001    exam  1    1
1001    exam  2    1
1001    exam  4    0
1001    exam  36   1
1001    exam  103  1

1001    lab   0    0
1001    lab   1    1
1001    lab   2    1
1001    lab   4    0
1001    lab   30   0
1001    lab   100  1&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;With a structure like that, it's much easier to work with.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 16:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873216#M345009</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-05-01T16:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873219#M345010</link>
      <description>below is the code to create the list of missing values. the problem is that the list of days expected are not inclusive of when the day is -1(+1) or 28 (+2) ect. There are also about 10 different forms with different criteria on days expected.&lt;BR /&gt;&lt;BR /&gt;*check between list variables;&lt;BR /&gt;data missing_days;&lt;BR /&gt;set check_formdays;&lt;BR /&gt;length Days_missing $1000;&lt;BR /&gt;do index=1 to countw(days_expected,',');&lt;BR /&gt;if not findw(day_intended,scan(days_expected,index,','),',','T') then&lt;BR /&gt;days_missing=catx(',',days_missing,scan(days_expected,index,','))&lt;BR /&gt;;&lt;BR /&gt;end;&lt;BR /&gt;drop index;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 01 May 2023 17:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873219#M345010</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-05-01T17:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873220#M345011</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	if lowcase(strip(form)) eq 'exam' then do;
		num= countc(days, ',');
		do i=1 to num+1;
			temp= input(scan(days, i, ','), best.);
			if temp eq 3 then do;
				count= countc(days_missing, ',');
				do k=1 to count+1;
					if input(scan(days_missing, k, ','), best.) eq 0 then days_missing= tranwrd(days_missing,scan(days_missing, k, ','), '');
				end; 
			end; 
			else if temp eq 1 then do;
				count= countc(days_missing, ',');
				do k=1 to count+1;
					if input(scan(days_missing, k, ','), best.) eq 4 then days_missing= tranwrd(days_missing,scan(days_missing, k, ','), '');
				end; 
			end; 
		end;
	end; 
	else if lowcase(strip(form)) eq 'lab' then do;
		num= countc(days, ',');
		do i=1 to num+1;
			temp= input(scan(days, i, ','), best.);
			if temp eq 1 then do;
				count= countc(days_missing, ',');
				do k=1 to count+1;
					if input(scan(days_missing, k, ','), best.) eq 0 then days_missing= tranwrd(days_missing,scan(days_missing, k, ','), '');
				end; 
			end; 
		end;
	end; 
	if substr(strip(days_missing), 1, 1) eq ',' then days_missing=substrn(strip(days_missing), 2);
	drop num temp count i k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2023 17:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873220#M345011</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-05-01T17:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873225#M345012</link>
      <description>&lt;P&gt;for the second row, it gets days_missing='4,3' rather than '4,30'&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 17:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873225#M345012</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-05-01T17:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873278#M345028</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;do you have a better solution?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since we now have separate step from the original question of "determine days missing" I would say to place the values of days missing into an array, possibly temporary. Then we have NUMERIC values and can match them to (input(scan(days,i)) type code.&lt;/P&gt;
&lt;P&gt;Which I would suggest doing at creating days missing instead of continuing with a poor data approach to begin with.&lt;/P&gt;
&lt;P&gt;Perhaps after all the rules (any bets we get at least one more set related to this?) have been applied it &lt;STRONG&gt;might&lt;/STRONG&gt; be worth sticking multiple values into a single one.&lt;/P&gt;
&lt;P&gt;Really reading all of days, expected days into arrays likely makes this a BUNCH simpler in the long run than attempting to deal with character strings.&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 15:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873278#M345028</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-02T15:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873387#M345086</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Use a regular expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   length days_missing2 $30;
   days_missing2=days_missing;
   if form in ('exam' 'lab') then do;
      days_missing2=prxchange('s/\D0(?!\d)//',-1,days_missing2);
      days_missing2=prxchange('s/(?&amp;lt;!\d)0\D//',-1,days_missing2);
   end;
   if form='exam' then do;
      days_missing2=prxchange('s/\D4(?!\d)//',-1,days_missing2);
      days_missing2=prxchange('s/(?&amp;lt;!\d)4\D//',-1,days_missing2);
   end;
run;&lt;/CODE&gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 14:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873387#M345086</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-02T14:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873408#M345096</link>
      <description>&lt;P&gt;I find regular expressions are still underused by most SAS programmers. Great solution!&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2023 15:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873408#M345096</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-05-02T15:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Search for character in a list and remove it</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873549#M345163</link>
      <description>&lt;P&gt;Edit: the check on days must be added&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   length days_missing2 $30;
   days_missing2=days_missing;
   if form in ('exam' 'lab') and prxmatch('/(?&amp;lt;!\d)1(?!\d)/',days) then do;
      days_missing2=prxchange('s/\D0(?!\d)//',-1,days_missing2);
      days_missing2=prxchange('s/(?&amp;lt;!\d)0\D//',-1,days_missing2);
   end;
   if form='exam' and prxmatch('/(?&amp;lt;!\d)3(?!\d)/',days)then do;
      days_missing2=prxchange('s/\D4(?!\d)//',-1,days_missing2);
      days_missing2=prxchange('s/(?&amp;lt;!\d)4\D//',-1,days_missing2);
   end;
run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 07:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Search-for-character-in-a-list-and-remove-it/m-p/873549#M345163</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-03T07:33:28Z</dc:date>
    </item>
  </channel>
</rss>

