- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a variable that contains details on how much medicine was administered for each patient during a stay at the hospital and I need to clean some observations.
Examples of clean observations are: 2 GRAMS, 20 OUNCE
for these clean examples, I create two variables one for the quantity and one for the unit.
But some observations are: 4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY.
For these examples, I need to remove ONLY TODAY, and then I can separate the quantity and unit values using COMPRESS
quantity=compress(DrugQuantity,"1234567890./","k");
unit=compress(DrugQuantity,"ABCDEFGHIJKLMNOPQRSTUVWXYZ ","k");
How can I remove all those ONLY TODAY parts from my original variable or from my compressed unit variable? I appreciate your suggestions.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think this calls for PRXCHANGE. If someone notices an issue with my regex, please feel free to correct it.
Errors may pop up depending on whether the words are consistently spelled the way you showed them.
data have;
var = "4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY";
run;
data want;
set have;
want_var = prxchange("s/\s*?(ONLY TODAY)\s*?//", -1, var);
run;
Obs var want_var 1 4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY 4 GRAMS, 15 OUNCE
The
\s*?
checks for zero or more spaces before or after the phrase ONLY TODAY.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think this calls for PRXCHANGE. If someone notices an issue with my regex, please feel free to correct it.
Errors may pop up depending on whether the words are consistently spelled the way you showed them.
data have;
var = "4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY";
run;
data want;
set have;
want_var = prxchange("s/\s*?(ONLY TODAY)\s*?//", -1, var);
run;
Obs var want_var 1 4 GRAMS ONLY TODAY, 15 OUNCE ONLY TODAY 4 GRAMS, 15 OUNCE
The
\s*?
checks for zero or more spaces before or after the phrase ONLY TODAY.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks very much @maguiremq. your solution works perfectly! Thanks