Need to compare two columns either complete or partial. This can be achived using regex,but do not want to hardcode the values as I need to compare 100's of records.
for instance:
ColA ColB
AE AE_NCI
AE CM_AE
AE SAE_SUPP
the colA has the string "AE" , if Colb has complete or partial that assign value as 1 . There are 100's of rows with different values that need to compared.
usual way is if prxmatch("/ae/oi",colb)>0 then value=1. but here ae is hardcoded. anyway to dymaically pass colA into prxmatch function?
I agree with @SuryaKiran. If your colA includes leading and trailing blanks, then use the strip function. However, then remove the t option as it will only cause the process to slow down. i.e.:
data want; set have; if find(ColB,strip(ColA),'i') then value=1; else value=0; run;
Art, CEO, AnalystFinder.com
p.s., @SASPhile: This is ArtT not ArtC
FINDW or INDEXW?
SAE_SUPP is not resulted out
How about:
data have; input (ColA ColB) ($); cards; AE AE_NCI AE CM_AE AE SAE_SUPP AE AB_NCI AB AB_NCI AB CM_AE AB SAB_SUPP ; data want; set have; if find(ColB,ColA,'it') then value=1; else value=0; run;
Art, CEO, AnalystFinder.com
Artc, I'm getting the value 0 for all records
find(ColB,STRIP(ColA),'it')
Remove leading and trailing blanks.
I agree with @SuryaKiran. If your colA includes leading and trailing blanks, then use the strip function. However, then remove the t option as it will only cause the process to slow down. i.e.:
data want; set have; if find(ColB,strip(ColA),'i') then value=1; else value=0; run;
Art, CEO, AnalystFinder.com
p.s., @SASPhile: This is ArtT not ArtC
Like this?
data HAVE;
input COLA $ COLB $;
A= prxmatch(catt('/(',COLA,')/i'),COLB);
putlog A=;
cards;
AE AE_NCI
AE CM_AE
AE SAE_SUPP
AX SAE_SUPP
run;
A=1
A=4
A=2
A=0
RegEx are more expensive than functions like FIND though.
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 16. 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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: