Hi everyone,
I have string data in two columns that are separated by commas. I'd like to scan the first column's characters and see if it appears in the second column.
Here is some sample data:
| HaveA | HaveB |
| Homeless, Health Care, Aided | Health Care, Verified, Aided |
| A,B,C | A,C |
| X,Y,Z | J,K,F |
This is what I want:
| HaveA | HaveB | Want |
| Homeless, Health Care, Aided | Health Care, Verified, Aided | Health Care, Aided |
| A,B,C | A,C | A,C |
| X,Y,Z | J,K,F | . |
Many thanks in advance!
Untested without data but has a chance of to get started.
data want;
set have;
length wantstr $100; /* or long enough to hold expected longest value*/
do i= 1 to countw(HaveA,',');
if index(haveb, scan(havea,i,','))>0 then wantstr=catx(',',wantstr,scan(havea,i,','));
end;
drop i;
run;
Countw and Scan functions are told to only consider comma as delimiter for finding phrases,
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.