I want to return any observation that contains the word "med" in any place in a variable
id desc
1 one medication at a time
2 two medication at a time
3 none
output
1
2
If I may be so bold as to suggest an improvement to the code
if find(desc,'med','i')>0;
This finds the letters med regardless of whether they are uppercase or lowercase.
data have;
input ID desc & $30. ;
cards;
1 one medication at a time
2 two medication at a time
3 none
;
data want;
set have;
if find(desc,'med')>0;
run;
If I may be so bold as to suggest an improvement to the code
if find(desc,'med','i')>0;
This finds the letters med regardless of whether they are uppercase or lowercase.
@PaigeMiller wrote:
If I may be so bold as to suggest an improvement to the code
Of course stat champ sir. i always am in awe of your quantitative acumen on stats domain. Fall qtr starts tomorrow as PCA, logistic will go full throttle.Will reach out for guidance and help on that thread https://communities.sas.com/t5/SAS-Statistical-Procedures/Requesting-guidance-for-Principal-componen.... 🙂 have a great evening
Thank you, the upper/lower case addition is much needed!
> I want to return any observation that contains the word "med" in any place in a variable
"med" is not a word in your example, just a substring. "medication" is a word.
Looking for words is different than looking for strings. Be careful and exact when phrasing your questions.
Another possibility is to use a WHERE clause. May be faster:
data want;
set have;
where desc like '%med%';
run;
Or, if you want both upper and lowercase:
data want;
set have;
where upcase(desc) like '%MED%';
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: