BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ChickenLittle
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 621 views
  • 1 like
  • 2 in conversation