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")
What is your question?
The code is not working. Can you help come up with a code that give me the output as displayed above.
edu = find(EDucation,'MD')>0;
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.
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;
In the above code:
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:
edu = FIND(Education,"MD","i");
or
edu = FINDW(Education,"MD"," ,","i");
Best,
Is it possible you have an old version of SAS. Find was introduced with version 9. Try Index
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;
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.