Hi,
I need to check tow strings for occurances of blank, 'U', and 'UU'. If both strings contain, then newvar ='Unknown'.
I tried using find and Index...both getting error. Can someone please tell me how to write this correctly?
if find(mhdxm_1,' ','U','UU')>0 and find(mhdxy_2,' ','U','UU')>0 then mhendtc='UNKNOWN';
Thanks!
Is there any real reason to complicate this logic with the use of FIND? Unless you have values that are right-hand-justified, you can simply use:
if mhdxm_1 in (' ' 'U' 'UU') and mhdxm_2 in (' ' 'U' 'UU') then mhendtc='UNKNOWN';
Are things actually more complex than that?
Find (or index in your previously deleted post) can only search for one target string at a time.
Your really should post code with errors from the log to show the details.
Note that unless you are missing an additional rule anything that finds 'U' doesn't need to search for 'UU' as the singe U will be found in UU. If there were a third different string such a 'RW' then a third search would be needed.
find(mhdxm_1,' ','U','UU')>0 should be
(find(mhdxm_1,' ',)>0 OR find(mhdxm_1,'U')>0)
exercise for the interested reader to complete the search of the other variable.
Your second argument has to be what your looking for and FIND function can search only one instance.
Try this:
if (find(mhdxm_1,'U','i')>0 and find(mhdxy_2,'U','i')>0) OR (find(mhdxm_1,'UU','i')>0 and find(mhdxy_2,'UU','i')>0) then mhendtc='UNKNOWN';
OR
use prxmatch()
prxmatch("m/U|UU/oi,mhdxm_1)>0 or prxmatch("m/U|UU/oi,mhdxm_2)>0
Is there any real reason to complicate this logic with the use of FIND? Unless you have values that are right-hand-justified, you can simply use:
if mhdxm_1 in (' ' 'U' 'UU') and mhdxm_2 in (' ' 'U' 'UU') then mhendtc='UNKNOWN';
Are things actually more complex than that?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.