BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jenim514
Pyrite | Level 9

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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?

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

SuryaKiran
Meteorite | Level 14

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

Thanks,
Suryakiran
Astounding
PROC Star

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?

sas-innovate-2024.png

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.

 

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
  • 3 replies
  • 701 views
  • 0 likes
  • 4 in conversation