<?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 compare delimited text in a column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833692#M329586</link>
    <description>Thanks so much! That is exactly what I am looking for. I replaced 10 with the largest known number from my data and it works as I expected. Thanks so much for your help!&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Le</description>
    <pubDate>Thu, 15 Sep 2022 17:32:23 GMT</pubDate>
    <dc:creator>binhle50</dc:creator>
    <dc:date>2022-09-15T17:32:23Z</dc:date>
    <item>
      <title>How to compare delimited text in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833610#M329553</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a diagnosis_combine variable that contains multiple diagnoses separated by " | " . I need to create the variable "want" to scan over the&amp;nbsp;diagnosis_combine to see if all diagnoses are the same or different as below:&lt;/P&gt;
&lt;TABLE width="622"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;Diagnosis_combine&lt;/TD&gt;
&lt;TD width="103"&gt;want&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;Ehlers-Danlos syndrome&lt;/TD&gt;
&lt;TD&gt;same&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;Storage Pool Disease | Storage Pool Disease | Factor I, hereditary | Storage Pool Disease | Storage Pool Disease&lt;/TD&gt;
&lt;TD&gt;different&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary&lt;/TD&gt;
&lt;TD&gt;same&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;vWD, type 2A | Factor I, hereditary&lt;/TD&gt;
&lt;TD&gt;different&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary&lt;/TD&gt;
&lt;TD&gt;same&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;Factor XIII, hereditary | Factor VIII, hereditary&lt;/TD&gt;
&lt;TD&gt;same&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="519"&gt;vWD, type 1 |&amp;nbsp; Storage Pool Disease&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;I would highly appreciate if you can help with the best SAS procedures to do it without having to separate&amp;nbsp;diagnosis_combine into multiple columns and compare all columns together.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Le&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:31:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833610#M329553</guid>
      <dc:creator>binhle50</dc:creator>
      <dc:date>2022-09-15T14:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare delimited text in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833631#M329563</link>
      <description>&lt;P&gt;Is there a known maximum number of diagnoses in that column?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Very likely a solution will involve creating additional variables and if there is not a known maximum then that will be a problem.&lt;/P&gt;
&lt;P&gt;With an array of variables it is not that hard to compare all of the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One example:&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines truncover;
   input Diagnosis_combine $100.;
datalines;
Ehlers-Danlos syndrome 	
Storage Pool Disease | Storage Pool Disease | Factor I, hereditary | Storage Pool Disease | Storage Pool Disease 	
Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary 	
vWD, type 2A | Factor I, hereditary 	
Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary 	
Factor XIII, hereditary | Factor VIII, hereditary 	
vWD, type 1 |  Storage Pool Disease 	
;

data want;
   set have;
   array d (10) $ 25;
   do i=1 to countw(Diagnosis_combine,'|');
      d[i] = strip(scan(Diagnosis_combine,i,'|'));
   end;
   length want $ 9;
   want='same';
   do i=1 to (countw(Diagnosis_combine,'|')-1);
      do j=(i+1) to (countw(Diagnosis_combine,'|'));
         if d[i] ne d[j] then do;
             want='different';
             leave;
         end;
      end;
   end;
   /* after verifying things are working then uncomment 
   the following line*/
/*   drop i j d1-d10;*/
run;&lt;/PRE&gt;
&lt;P&gt;The data step is to have something to work with.&lt;/P&gt;
&lt;P&gt;The array size should be the largest known (or expected) number of elements. Replace 10 with that number or "guess", you know your data better than we do.&lt;/P&gt;
&lt;P&gt;The first do loop pulls each value into a separate variable. The strip is make strings more consistent. It is likely that your actual data may not have a leading space for the value in the first position but does, if your paste is accurate, for those in other positions which would make them "different".&lt;/P&gt;
&lt;P&gt;The nested Do i and Do j compares the first value with the "remaining". In the case of only one value the first limit means no comparison is actually attempted.&lt;/P&gt;
&lt;P&gt;The LEAVE instruction says to leave the loops when the first not equal value is found.&lt;/P&gt;
&lt;P&gt;Drop the variables you don't need when done.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 15:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833631#M329563</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-15T15:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare delimited text in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833692#M329586</link>
      <description>Thanks so much! That is exactly what I am looking for. I replaced 10 with the largest known number from my data and it works as I expected. Thanks so much for your help!&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Le</description>
      <pubDate>Thu, 15 Sep 2022 17:32:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833692#M329586</guid>
      <dc:creator>binhle50</dc:creator>
      <dc:date>2022-09-15T17:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare delimited text in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833822#M329653</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines truncover;
   input Diagnosis_combine $100.;
datalines;
Ehlers-Danlos syndrome  
Storage Pool Disease | Storage Pool Disease | Factor I, hereditary | Storage Pool Disease | Storage Pool Disease  
Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary  
vWD, type 2A | Factor I, hereditary  
Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary | Factor I, hereditary  
Factor XIII, hereditary | Factor VIII, hereditary  
vWD, type 1 |  Storage Pool Disease  
;
data want;
 set have;
 want='different';
 if missing(compress(tranwrd(Diagnosis_combine,scan(Diagnosis_combine,1,'|'),''),'|')) then want='same';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 11:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833822#M329653</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-16T11:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare delimited text in a column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833845#M329667</link>
      <description>Thanks so much!!!&lt;BR /&gt;Yes it works great and it should be the most simple method.&lt;BR /&gt;Best,&lt;BR /&gt;Le</description>
      <pubDate>Fri, 16 Sep 2022 13:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-compare-delimited-text-in-a-column/m-p/833845#M329667</guid>
      <dc:creator>binhle50</dc:creator>
      <dc:date>2022-09-16T13:20:35Z</dc:date>
    </item>
  </channel>
</rss>

