For Example:
vend_net
406,800,802,803,8010
406,800,802,803,8010
Pract_net
406,800,802,803
406,800,803,8010
Expected ANS:
DIFF
8010
802
So how to find difference value between two column. Can you help me?
This produces the original answer. Although you might want to also search in the opposite direction.
data have ;
length vend_net Pract_net Expected $200;
input vend_net Pract_net Expected;
cards;
406,800,802,803,8010 406,800,802,803 8010
406,800,802,803,8010 406,800,803,8010 802
;
data want;
set have;
length diff $200;
do i=1 to countw(vend_net,', ');
if not indexw(Pract_net,scan(vend_net,i,', '),', ') then
diff=catx(',',scan(vend_net,i,', '))
;
end;
run;
proc print;
run;
Obs vend_net Pract_net Expected diff i 1 406,800,802,803,8010 406,800,802,803 8010 8010 6 2 406,800,802,803,8010 406,800,803,8010 802 802 6
It is not clear how your data actually looks.
Do you have a character variable with values separated by commas? YES
Multiple observations? YES
Multiple variables? Two Variable
It is also not clear what your logic is that generates that answer. It has to find out different value between two variable in one SAS datasets.
This produces the original answer. Although you might want to also search in the opposite direction.
data have ;
length vend_net Pract_net Expected $200;
input vend_net Pract_net Expected;
cards;
406,800,802,803,8010 406,800,802,803 8010
406,800,802,803,8010 406,800,803,8010 802
;
data want;
set have;
length diff $200;
do i=1 to countw(vend_net,', ');
if not indexw(Pract_net,scan(vend_net,i,', '),', ') then
diff=catx(',',scan(vend_net,i,', '))
;
end;
run;
proc print;
run;
Obs vend_net Pract_net Expected diff i 1 406,800,802,803,8010 406,800,802,803 8010 8010 6 2 406,800,802,803,8010 406,800,803,8010 802 802 6
By "difference" do you mean a substring separated by comma that appears in one value but not the other?
What do you want for result if there is no difference? If there are two or more differences?
And what do you mean by "regardless of row orders"? Do you mean that you have to compare every value of one variable with every value of the other? You should probably show an example with more than 2 rows of data and the exact expected value for all of the comparisons showing both the starting values for both variables and the desired result. Include at least one example that would have NO difference so we can see what you expect as a result in that case.
Also, are these variables in the same data set or different data sets?
Expecting the above example.
@Spintu wrote:
Expecting the above example.
Still don't see any definition of what "regardless of row orders" means. It appears that only wanted to compare within a single observation (row).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.