BookmarkSubscribeRSS Feed
knargis160
Calcite | Level 5

Hi 

edu = FINDC(Education,"MD"); 

 

Datalines 

Ptid  EDucation

1.     MD,DO

2.     MD

3.     PHD

 

How I want to code

Ptid  EDucation  edu 

1.     MD,DO      1

2.     MD            1

3.     PHD          0

 

edu = Find(Education, "MD")

 

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

What is your question?

--
Paige Miller
knargis160
Calcite | Level 5

The code is not working. Can you help come up with a code that give me the output as displayed above.

PaigeMiller
Diamond | Level 26
edu = find(EDucation,'MD')>0;
--
Paige Miller
Kurt_Bremser
Super User

Why are you using the findC function, which searches for single characters?

Rather use find, which searches for strings, or findw, which searches for words.

ed_sas_member
Meteorite | Level 14

Hi @knargis160 

 

 

data have;
	input Ptid $  EDucation $;
	edu = FINDC(Education,"MD"); 
	edu1 = FIND(Education,"MD"); 
	edu2 = FINDW(Education,"MD"); 
	datalines;
1.     MD,DO
2.     MD
3.     PHD
;
run;

Capture d’écran 2020-03-07 à 16.58.17.png

 

In the above code:

  • FINDC is looking for either "M" or "D" (-> it looks for each character in the list you provide)
  • FIND is looking for the substring "MD" either as a word or in a string (case sensitive) 
  • FINDW is looking for the substring "MD" as a word (case sensitive)

In your example, FIND and FINDW are equivalent, but if you had "MD" has part of a word, it would give different results.

 

NB: if you want to make a broader search and look at MD / md / MD / Md, you can add the 'i' modifier: 

  • In the FIND function, it should be the third argument:
edu = FIND(Education,"MD","i"); 

or 

  • In the FINDW function, it should be the 4th argument (the 3rd specifies the separators between words):
edu = FINDW(Education,"MD"," ,","i"); 

Best,

ghosh
Barite | Level 11

Is it possible you have an old version of SAS.  Find was introduced with version 9.  Try Index

 

index.png

data x;
input Ptid  Education $char10.;
edu_f = FIND(Education,"MD")>0; 
edu_i = INDEX(Education,"MD")>0; 
Datalines ;
1.     MD,DO
2.     MD
3.     PHD
;
proc print;run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 917 views
  • 1 like
  • 5 in conversation