<?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 find the difference from two columns which contains comma separated values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663464#M198056</link>
    <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21414"&gt;@ed&lt;/a&gt;_sas_master,&lt;BR /&gt;&lt;BR /&gt;Thanks for your efforts.&lt;BR /&gt;&lt;BR /&gt;i need your help more on this,&lt;BR /&gt;&lt;BR /&gt;data mydata_long;&lt;BR /&gt;set mydata;&lt;BR /&gt;do i=1 to countw(a,',');&lt;BR /&gt;a1 = scan(a,i);&lt;BR /&gt;b1 = scan(b,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;keep a1 b1 id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;if the length of a and b varies the output diff will also get changed.&lt;BR /&gt;&lt;BR /&gt;ex: if column a contains 205,8010 and column b contains 205,200,102 in this case the above code won't work.&lt;BR /&gt;&lt;BR /&gt;do i=1 to countw(a,','); in this scenario Column A contains 2 and B contains 3 values.&lt;BR /&gt;as per this it will skip the 3rd value and process with other.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Fri, 19 Jun 2020 12:52:32 GMT</pubDate>
    <dc:creator>sarav93</dc:creator>
    <dc:date>2020-06-19T12:52:32Z</dc:date>
    <item>
      <title>how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663440#M198042</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Good Evening,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that has two columns A and B which having comma separated values. i wanted to compare these two columns A and B and i need to take the difference in both these columns and capture it in a new column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Shown below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarav93_0-1592566689624.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46384i7E40B91ED94C9DA3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarav93_0-1592566689624.png" alt="sarav93_0-1592566689624.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sarav&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 11:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663440#M198042</guid>
      <dc:creator>sarav93</dc:creator>
      <dc:date>2020-06-19T11:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663450#M198044</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327203"&gt;@sarav93&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data mydata;
	input a:$30. b:$30.;
	id+1;
	datalines;
61,213,625,637,8010 61,625,637,650,8010
61,213,625,650,8010 61,213,637,650,8010
;

data mydata_long;
	set mydata;
	do i=1 to countw(a,',');
		a1 = scan(a,i);
		b1 = scan(b,i);
		output;
	end;
	keep a1 b1 id;
run;

proc sql;
	create table diff as
	(select id, a1 from mydata_long
	except 
	select id, b1 from mydata_long)
	union 
	(select id, b1 from mydata_long
	except 
	select id, a1 from mydata_long);
quit;

data diff2 (keep=id expected);
	do until (last.ID);
		set diff;
		by id;
		length expected $50.;
		expected = catx(",",expected,a1);
	end;
run;

proc sql;
	create table want as
	select a, b, expected
	from mydata as a full join diff2 as b
	on a.ID = b.ID;
quit;
	&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 12:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663450#M198044</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-06-19T12:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663453#M198046</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327203"&gt;@sarav93&lt;/a&gt;&amp;nbsp; The process seems rather straight forward linear search to me-&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
	input a:$30. b:$30.;
	datalines;
61,213,625,637,8010 61,625,637,650,8010
61,213,625,650,8010 61,213,637,650,8010
;


data want;
 set mydata;
 array t(999)$100 _temporary_;
 array u(999)$100 _temporary_;
 call missing(of t(*),of u(*));
 do _n_=1 to countw(b,',');
  temp=scan(b,_n_,',');
  if ^index(a,strip(temp)) then t(_n_)=temp;
 end;
 do _n_=1 to countw(a,',');
  temp=scan(a,_n_,',');
  if ^index(b,strip(temp)) then u(_n_)=temp;
 end;
 length want $100;
 want=catx(',',of u(*),of t(*));
 drop temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 13:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663453#M198046</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-19T13:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663464#M198056</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21414"&gt;@ed&lt;/a&gt;_sas_master,&lt;BR /&gt;&lt;BR /&gt;Thanks for your efforts.&lt;BR /&gt;&lt;BR /&gt;i need your help more on this,&lt;BR /&gt;&lt;BR /&gt;data mydata_long;&lt;BR /&gt;set mydata;&lt;BR /&gt;do i=1 to countw(a,',');&lt;BR /&gt;a1 = scan(a,i);&lt;BR /&gt;b1 = scan(b,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;keep a1 b1 id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;if the length of a and b varies the output diff will also get changed.&lt;BR /&gt;&lt;BR /&gt;ex: if column a contains 205,8010 and column b contains 205,200,102 in this case the above code won't work.&lt;BR /&gt;&lt;BR /&gt;do i=1 to countw(a,','); in this scenario Column A contains 2 and B contains 3 values.&lt;BR /&gt;as per this it will skip the 3rd value and process with other.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 19 Jun 2020 12:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663464#M198056</guid>
      <dc:creator>sarav93</dc:creator>
      <dc:date>2020-06-19T12:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663507#M198078</link>
      <description>&lt;P&gt;/*Or*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data mydata;
	input a:$30. b:$30.;
	datalines;
61,213,625,637,8010 61,625,637,650,8010
61,213,625,650,8010 61,213,637,650,8010
;


data want;
 set mydata;
 length want $100;
 do _n_=1 to countw(b,',');
  temp=scan(b,_n_,',');
  if ^index(a,strip(temp)) then want=catx(',',want,temp);
 end;
 do _n_=1 to countw(a,',');
  temp=scan(a,_n_,',');
  if ^index(b,strip(temp)) then want=catx(',',want,temp);
 end;
 drop temp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 14:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663507#M198078</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-06-19T14:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663524#M198084</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327203"&gt;@sarav93&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're absolutely right.&lt;/P&gt;
&lt;P&gt;In my previous code, I made the assumption that there was the same number of values in a and b.&lt;/P&gt;
&lt;P&gt;If they can be different, you can modify the do loop statement as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to max(countw(a,','), countw(b,','));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 15:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663524#M198084</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-06-19T15:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663527#M198087</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327203"&gt;@sarav93&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21414"&gt;@ed&lt;/a&gt;_sas_master,&lt;BR /&gt;&lt;BR /&gt;Thanks for your efforts.&lt;BR /&gt;&lt;BR /&gt;i need your help more on this,&lt;BR /&gt;&lt;BR /&gt;data mydata_long;&lt;BR /&gt;set mydata;&lt;BR /&gt;do i=1 to countw(a,',');&lt;BR /&gt;a1 = scan(a,i);&lt;BR /&gt;b1 = scan(b,i);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;keep a1 b1 id;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;if the length of a and b varies the output diff will also get changed.&lt;BR /&gt;&lt;BR /&gt;ex: if column a contains 205,8010 and column b contains 205,200,102 in this case the above code won't work.&lt;BR /&gt;&lt;BR /&gt;do i=1 to countw(a,','); in this scenario Column A contains 2 and B contains 3 values.&lt;BR /&gt;as per this it will skip the 3rd value and process with other.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Doesn't work" does not explain what is actually needed. Please provide rules.&lt;/P&gt;
&lt;P&gt;And example data that represents all of the potential cases that are in your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to provide rules for what gets added to what when the string element list counts differ. If one has 3 elements and the other 2 it is not obvious to me which values get added to what. The short one might mean that that the first value is supposed to be added to second of the longer, or that the second of the shorter gets added to the third of the longer. And what about 6 elements in and 2 in the other? There are getting to be potentially a moderate number of cases that need to be considered. So, exactly what is the rule on how to combine non-matching number of elements? And you need rules that handle every possible mismatched number in your data if any of the rules ever involve processing one out of order.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 15:51:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663527#M198087</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-19T15:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663685#M198178</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327203"&gt;@sarav93&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did any of the replies give you the answer you need. If so then please mark it as solution; If not please tell us what's still missing/not working.&lt;/P&gt;
&lt;P&gt;Also: Please don't paste sample data as a screenshot but provide a SAS data step which creates such data like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;has done for you. That's just so we can spend the time resolving your challenge and provide tested code instead of spending the time creating sample data.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 07:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663685#M198178</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-20T07:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663932#M198300</link>
      <description>thankyou !!! &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 22 Jun 2020 08:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663932#M198300</guid>
      <dc:creator>sarav93</dc:creator>
      <dc:date>2020-06-22T08:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to find the difference from two columns which contains comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663933#M198301</link>
      <description>sure Patrick.</description>
      <pubDate>Mon, 22 Jun 2020 08:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-the-difference-from-two-columns-which-contains-comma/m-p/663933#M198301</guid>
      <dc:creator>sarav93</dc:creator>
      <dc:date>2020-06-22T08:50:37Z</dc:date>
    </item>
  </channel>
</rss>

