Hi, what is the most efficient way to grab each unique value from FieldABC for every person listed(i.e. AB and then CD and then EF then GH, etc without duplicates). And then either do option 1 or option 2 as follows:
Option1: Set up a macro to go through each of those unique values to produce a proc freq between FieldABC and FieldXYZ to see where there are matches.
Option2: Do a proc freq displaying all the unique values from FieldABC vs FieldXYZ to see where there are matches.
The table set up looks like this:
Person FieldABC FieldXYZ
PersonA AB CD;EF
PersonB CD;EF;GH EF;GH
PersonC AB;EF AB;
PersonD CD EF;GH
Result would look something like this:
AB CD EF GH
AB 1 0 0 0
CD 0 0 0 0
EF 0 0 1 0
GH 0 0 0 1
Or results could be something like this:
For value ‘AB’
Field XYZ
FieldABC 1
For value ‘EF’
Field XYZ
FieldABC 1
Normalize the data and then just count.
data tall;
set have;
do index=1 to countw(fieldabc,';');
word = scan(fieldabc,index,';');
output;
end;
do index=1 to countw(fieldxyz,';');
word = scan(fieldxyz,index,';');
output;
end;
keep person word;
run;
proc freq ;
tables person*word / noprint out=counts;
run;
Normalize the data and then just count.
data tall;
set have;
do index=1 to countw(fieldabc,';');
word = scan(fieldabc,index,';');
output;
end;
do index=1 to countw(fieldxyz,';');
word = scan(fieldxyz,index,';');
output;
end;
keep person word;
run;
proc freq ;
tables person*word / noprint out=counts;
run;
Thanks!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.