- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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")
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What is your question?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The code is not working. Can you help come up with a code that give me the output as displayed above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
edu = find(EDucation,'MD')>0;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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:
- 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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;