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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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