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?
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 25. 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.